tobotras

Untitled

Dec 21st, 2022
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. import base64
  2. import cryptography.exceptions
  3. from cryptography.hazmat.backends import default_backend
  4. from cryptography.hazmat.primitives import hashes
  5. from cryptography.hazmat.primitives.asymmetric import padding
  6. from cryptography.hazmat.primitives.serialization import load_pem_public_key
  7.  
  8. import sys
  9. if len(sys.argv) != 2:
  10.     print("No file to validate", file=sys.stderr)
  11.     exit(1)
  12.  
  13. # Load the public key.
  14. with open('public.pem', 'rb') as f:
  15.     public_key = load_pem_public_key(f.read(), default_backend())
  16.  
  17. # Load the payload contents and the signature.
  18. with open(sys.argv[1], 'rb') as f:
  19.     payload_contents = f.read()
  20. with open('signature.sig', 'rb') as f:
  21.     signature = base64.b64decode(f.read())
  22.  
  23. # Perform the verification.
  24. try:
  25.     public_key.verify(
  26.         signature,
  27.         payload_contents,
  28.         padding.PKCS1v15(),
  29.         hashes.SHA256(),
  30.     )  
Add Comment
Please, Sign In to add comment