verify¶
-
KeyManager.
verify
(signature: Union[str, bytes], message: Union[str, bytes], pad=None, hashing: cryptography.hazmat.primitives.hashes.HashAlgorithm = <cryptography.hazmat.primitives.hashes.SHA256 object>) → bool[source]¶ Verify a signature against a given message using an asymmetric public key.
>>> km = KeyManager.load_keyfile('id_rsa') >>> sig = km.sign('hello world') # Sign 'hello world' using the id_rsa private key >>> try: ... km.verify(sig, 'hello world') # Verify it using the public key (automatically generated) ... print('Signature is valid') >>> except cryptography.exceptions.InvalidSignature: ... print('Signature IS NOT VALID!')
- Parameters
signature (str|bytes) – The binary, or base64 urlsafe encoded signature to check
message
againstmessage (str|bytes) – The message to verify, e.g.
hello world
pad – (RSA only) An instance of a cryptography padding class, e.g.
padding.PSS
hashing (HashAlgorithm) – (ECDSA/RSA) Use this hashing method for padding/signatures
- Raises
cryptography.exceptions.InvalidSignature – When the signature does not match the message
- Return bool is_valid
True
if signature is valid, otherwise raises InvalidSignature.