MCPcopy Create free account
hub / github.com/awsdocs/aws-doc-sdk-examples / verify

Method verify

python/example_code/kms/key_encryption.py:148–175  ·  view source on GitHub ↗

Verifies a signature against a message. :param key_id: The ARN or ID of the key used to sign the message. :param message: The message to verify. :param signature: The signature to verify. :return: True when the signature matches the message, otherwise False.

(self, key_id: str, message: str, signature: str)

Source from the content-addressed store, hash-verified

146
147 # snippet-start:[python.example_code.kms.Verify]
148 def verify(self, key_id: str, message: str, signature: str) -> bool:
149 """
150 Verifies a signature against a message.
151
152 :param key_id: The ARN or ID of the key used to sign the message.
153 :param message: The message to verify.
154 :param signature: The signature to verify.
155 :return: True when the signature matches the message, otherwise False.
156 """
157 try:
158 response = self.kms_client.verify(
159 KeyId=key_id,
160 Message=message.encode(),
161 Signature=signature,
162 SigningAlgorithm="RSASSA_PSS_SHA_256",
163 )
164 valid = response["SignatureValid"]
165 print(f"The signature is {'valid' if valid else 'invalid'}.")
166 return valid
167 except ClientError as err:
168 if err.response["Error"]["Code"] == "SignatureDoesNotMatchException":
169 print("The signature is not valid.")
170 else:
171 logger.error(
172 "Couldn't verify your signature. Here's why: %s",
173 err.response["Error"]["Message"],
174 )
175 raise
176
177 # snippet-end:[python.example_code.kms.Verify]
178

Callers 4

kms_scenarioMethod · 0.80
signVerifyDataAsyncMethod · 0.80
validateDigestFileMethod · 0.80

Calls

no outgoing calls

Tested by 1