maroph icon

OpenSSL: Sign/Verify file

maroph | PRO | 04/26/17 07:11:04 AM UTC | 0 ⭐ | 655 👁️ | Never ⏰ | []
Bash |

820 B

|

None

|

0 👍

/

0 👎

# Create a private/public key pair (4096 bits RSA)
openssl genrsa -out key.pem 4096
 
# Check the private key
openssl rsa -check -noout -in key.pem
 
# Print the private key data
openssl rsa -text -noout -in key.pem
 
# Extract the public key
openssl rsa -in key.pem -pubout > public.pem
 
# Print the public key data
openssl pkey -inform PEM -pubin -text -noout -in public.pem
 
# Sign the file sample.txt
openssl dgst -sha256 -sign key.pem -out sample.txt.sig.sha256 sample.txt
 
# Verify the signature of file sample.txt
openssl dgst -sha256 -verify public.pem -signature sample.txt.sig.sha256 sample.txt
 
 
# You need a public key only file for the verification. If you have the certificate for the verification you
# can extract the public key from the certificate file
openssl x509 -in key.crt -pubkey -noout >public.pem

Comments