2424
2525# [START kms_get_asymmetric_public]
2626def 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]
4344def 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]
6063def 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]
7479def 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]
94102def 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]
118127def 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 )
0 commit comments