maroph

OpenSSL: Sign/Verify file

Apr 26th, 2017
599
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.82 KB | None | 0 0
  1. # Create a private/public key pair (4096 bits RSA)
  2. openssl genrsa -out key.pem 4096
  3.  
  4. # Check the private key
  5. openssl rsa -check -noout -in key.pem
  6.  
  7. # Print the private key data
  8. openssl rsa -text -noout -in key.pem
  9.  
  10. # Extract the public key
  11. openssl rsa -in key.pem -pubout > public.pem
  12.  
  13. # Print the public key data
  14. openssl pkey -inform PEM -pubin -text -noout -in public.pem
  15.  
  16. # Sign the file sample.txt
  17. openssl dgst -sha256 -sign key.pem -out sample.txt.sig.sha256 sample.txt
  18.  
  19. # Verify the signature of file sample.txt
  20. openssl dgst -sha256 -verify public.pem -signature sample.txt.sig.sha256 sample.txt
  21.  
  22.  
  23. # You need a public key only file for the verification. If you have the certificate for the verification you
  24. # can extract the public key from the certificate file
  25. openssl x509 -in key.crt -pubkey -noout >public.pem
Advertisement
Add Comment
Please, Sign In to add comment