Created
September 13, 2018 03:30
-
-
Save nghiaht/224f7fe04ea591c6d2fddbee6c173379 to your computer and use it in GitHub Desktop.
Generate RSA keypair (public, private + pkcs8) using openssl command
This file contains 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
# Private key | |
openssl genpkey -algorithm RSA -out private.pem -pkeyopt rsa_keygen_bits:2048 | |
# Public key | |
openssl rsa -pubout -in private.pem -out public_key.pem | |
# Private key in pkcs8 format (for Java maybe :D) | |
openssl pkcs8 -topk8 -in private.pem -out private_key.pem | |
## nocrypt (Private key does have no password) | |
openssl pkcs8 -topk8 -in private.pem -nocrypt -out private_key.pem |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It seems like the first and last command do exactly the same, because openssl changed their default format to pkcs#8, there is no convertion needed any longer.
$ openssl asn1parse -in private_key.pem -inform PEM
0:d=0 hl=4 l=1213 cons: SEQUENCE
4:d=1 hl=2 l= 1 prim: INTEGER :00
7:d=1 hl=2 l= 13 cons: SEQUENCE
9:d=2 hl=2 l= 9 prim: OBJECT :rsaEncryption
20:d=2 hl=2 l= 0 prim: NULL
22:d=1 hl=4 l=1191 prim: OCTET STRING
$ openssl asn1parse -in private.pem -inform PEM
0:d=0 hl=4 l=1213 cons: SEQUENCE
4:d=1 hl=2 l= 1 prim: INTEGER :00
7:d=1 hl=2 l= 13 cons: SEQUENCE
9:d=2 hl=2 l= 9 prim: OBJECT :rsaEncryption
20:d=2 hl=2 l= 0 prim: NULL
22:d=1 hl=4 l=1191 prim: OCTET STRING