Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import base64
- import cryptography.exceptions
- from cryptography.hazmat.backends import default_backend
- from cryptography.hazmat.primitives import hashes
- from cryptography.hazmat.primitives.asymmetric import padding
- from cryptography.hazmat.primitives.serialization import load_pem_public_key
- import sys
- if len(sys.argv) != 2:
- print("No file to validate", file=sys.stderr)
- exit(1)
- # Load the public key.
- with open('public.pem', 'rb') as f:
- public_key = load_pem_public_key(f.read(), default_backend())
- # Load the payload contents and the signature.
- with open(sys.argv[1], 'rb') as f:
- payload_contents = f.read()
- with open('signature.sig', 'rb') as f:
- signature = base64.b64decode(f.read())
- # Perform the verification.
- try:
- public_key.verify(
- signature,
- payload_contents,
- padding.PKCS1v15(),
- hashes.SHA256(),
- )
Add Comment
Please, Sign In to add comment