Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 790fd5f

Browse filesBrowse files
kms text fixes (GoogleCloudPlatform#1647)
1 parent c9f59bc commit 790fd5f
Copy full SHA for 790fd5f

File tree

Expand file treeCollapse file tree

2 files changed

+18
-8
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+18
-8
lines changed

‎kms/api-client/asymmetric.py

Copy file name to clipboardExpand all lines: kms/api-client/asymmetric.py
+17-7Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424

2525
# [START kms_get_asymmetric_public]
2626
def getAsymmetricPublicKey(client, key_path):
27-
"""Retrieves the public key from a saved asymmetric key pair on Cloud KMS
27+
"""
28+
Retrieves the public key from a saved asymmetric key pair on Cloud KMS
2829
"""
2930
request = client.projects() \
3031
.locations() \
@@ -41,7 +42,9 @@ def getAsymmetricPublicKey(client, key_path):
4142

4243
# [START kms_decrypt_rsa]
4344
def decryptRSA(ciphertext, client, key_path):
44-
"""Decrypt a given ciphertext using an RSA private key stored on Cloud KMS
45+
"""
46+
Decrypt a given ciphertext using an 'RSA_DECRYPT_OAEP_2048_SHA256' private
47+
key stored on Cloud KMS
4548
"""
4649
request = client.projects() \
4750
.locations() \
@@ -58,7 +61,9 @@ def decryptRSA(ciphertext, client, key_path):
5861

5962
# [START kms_encrypt_rsa]
6063
def encryptRSA(message, client, key_path):
61-
"""Encrypt message locally using an RSA public key retrieved from Cloud KMS
64+
"""
65+
Encrypt message locally using an 'RSA_DECRYPT_OAEP_2048_SHA256' public
66+
key retrieved from Cloud KMS
6267
"""
6368
public_key = getAsymmetricPublicKey(client, key_path)
6469
pad = padding.OAEP(mgf=padding.MGF1(algorithm=hashes.SHA256()),
@@ -72,8 +77,11 @@ def encryptRSA(message, client, key_path):
7277

7378
# [START kms_sign_asymmetric]
7479
def signAsymmetric(message, client, key_path):
75-
"""Create a signature for a message using a private key stored on Cloud KMS
7680
"""
81+
Create a signature for a message using a private key stored on Cloud KMS
82+
"""
83+
# Note: some key algorithms will require a different hash function
84+
# For example, EC_SIGN_P384_SHA384 requires SHA384
7785
digest_bytes = hashlib.sha256(message.encode('ascii')).digest()
7886
digest64 = base64.b64encode(digest_bytes)
7987

@@ -92,8 +100,9 @@ def signAsymmetric(message, client, key_path):
92100

93101
# [START kms_verify_signature_rsa]
94102
def verifySignatureRSA(signature, message, client, key_path):
95-
"""Verify the validity of an 'RSA_SIGN_PSS_2048_SHA256' signature
96-
for the specified plaintext message
103+
"""
104+
Verify the validity of an 'RSA_SIGN_PSS_2048_SHA256' signature for the
105+
specified plaintext message
97106
"""
98107
public_key = getAsymmetricPublicKey(client, key_path)
99108

@@ -116,7 +125,8 @@ def verifySignatureRSA(signature, message, client, key_path):
116125

117126
# [START kms_verify_signature_ec]
118127
def verifySignatureEC(signature, message, client, key_path):
119-
"""Verify the validity of an 'EC_SIGN_P224_SHA256' signature
128+
"""
129+
Verify the validity of an 'EC_SIGN_P256_SHA256' signature
120130
for the specified plaintext message
121131
"""
122132
public_key = getAsymmetricPublicKey(client, key_path)

‎kms/api-client/asymmetric_test.py

Copy file name to clipboardExpand all lines: kms/api-client/asymmetric_test.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def setup_module(module):
6464
s2 = create_key_helper(t.rsaSignId, t.rsaSign, 'ASYMMETRIC_SIGN',
6565
'RSA_SIGN_PSS_2048_SHA256', t)
6666
s3 = create_key_helper(t.ecSignId, t.ecSign, 'ASYMMETRIC_SIGN',
67-
'EC_SIGN_P224_SHA256', t)
67+
'EC_SIGN_P256_SHA256', t)
6868
if s1 or s2 or s3:
6969
# leave time for keys to initialize
7070
sleep(20)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.