24
24
25
25
# [START kms_get_asymmetric_public]
26
26
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
28
29
"""
29
30
request = client .projects () \
30
31
.locations () \
@@ -41,7 +42,9 @@ def getAsymmetricPublicKey(client, key_path):
41
42
42
43
# [START kms_decrypt_rsa]
43
44
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
45
48
"""
46
49
request = client .projects () \
47
50
.locations () \
@@ -58,7 +61,9 @@ def decryptRSA(ciphertext, client, key_path):
58
61
59
62
# [START kms_encrypt_rsa]
60
63
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
62
67
"""
63
68
public_key = getAsymmetricPublicKey (client , key_path )
64
69
pad = padding .OAEP (mgf = padding .MGF1 (algorithm = hashes .SHA256 ()),
@@ -72,8 +77,11 @@ def encryptRSA(message, client, key_path):
72
77
73
78
# [START kms_sign_asymmetric]
74
79
def signAsymmetric (message , client , key_path ):
75
- """Create a signature for a message using a private key stored on Cloud KMS
76
80
"""
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
77
85
digest_bytes = hashlib .sha256 (message .encode ('ascii' )).digest ()
78
86
digest64 = base64 .b64encode (digest_bytes )
79
87
@@ -92,8 +100,9 @@ def signAsymmetric(message, client, key_path):
92
100
93
101
# [START kms_verify_signature_rsa]
94
102
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
97
106
"""
98
107
public_key = getAsymmetricPublicKey (client , key_path )
99
108
@@ -116,7 +125,8 @@ def verifySignatureRSA(signature, message, client, key_path):
116
125
117
126
# [START kms_verify_signature_ec]
118
127
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
120
130
for the specified plaintext message
121
131
"""
122
132
public_key = getAsymmetricPublicKey (client , key_path )
0 commit comments