Last active
December 5, 2020 02:01
-
-
Save weihanglo/8fbe189b099c98c54f7509eee0f0e0c3 to your computer and use it in GitHub Desktop.
OpenSSL CheatSheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create X509 self-signed certificate. | |
openssl req \ | |
-newkey rsa:2048 -nodes -keyout cert.key \ | |
-x509 -days 365 -out cert.pem | |
# Convert from PEM format to DER. | |
openssl pkcs12 \ | |
-inkey cert.key -in cert.pem \ | |
-export -out cert.pfx | |
# Deserialize public key. | |
openssl x509 -pubkey -noout -in cert.pem > cert.pub | |
# Deserialize private key from PKCS#12/PFX. | |
openssl pkcs12 -in cert.pfx -nocerts | |
# Create secret data | |
echo "hello openssl" >> secret.txt | |
# "Encrypt" with public key. "Decrypt" with private key. | |
openssl rsautl -encrypt \ | |
-in secret.txt -out secret.enc \ | |
-pubin -inkey cert.pub | |
openssl rsautl -decrypt \ | |
-in secret.enc -inkey cert.key | |
# "Sign" with private key. "Verify" with public key. | |
openssl rsautl -sign \ | |
-in secret.txt -out secret.sign \ | |
-inkey cert.key | |
openssl rsautl -verify \ | |
-in secret.sign -pubin -inkey cert.pub | |
# hash digest | |
openssl dgst -md5 -binary -out md5.hash secret.txt # binary | |
openssl dgst -md5 -binary secret.txt | xxd -p > md5.hash # hex | |
# HMAC | |
openssl dgst -sha256 -binary -hmac "rust" -out sha256.hmac secret.txt # binary | |
openssl dgst -sha256 -binary -hmac "rust" secret.txt | xxd -p > sha256.hmac # hex |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment