In: Computer Science
Do the following with OpenSSL:
Use the appropriate command that generates this information and saves it in key.txt file.
How do I
generate an RSA key?
Use the genrsa option.
# default 1024-bit key, sent to standard output
openssl genrsa
# 2048-bit key, saved to file named mykey.pem
openssl genrsa -out mykey.pem 2048
# same as above, but encrypted with a passphrase
openssl genrsa -des3 -out mykey.pem 2048
How do I
generate a public RSA key?
Use the rsa option to produce a public version of your private RSA
key.
openssl rsa -in mykey.pem -pubout
openssl genrsa -out mykey.pem 1024
will actually produce a public - private key pair. The pair is
stored in the generated mykey.pem file.
openssl rsa -in mykey.pem -pubout > mykey.pub
will extract the public key and print that out
To just output the public part of a private key:
openssl rsa -in key.pem -pubout -out pubkey.pem
To get a usable public key for SSH purposes, use
ssh-keygen:
ssh-keygen -y -f key.pem > key.pub
RSA private key syntax
An RSA private key should be represented with the ASN.1
type
RSAPrivateKey:
RSAPrivateKey ::= SEQUENCE {
version Version,
modulus INTEGER, -- n
publicExponent INTEGER, -- e
privateExponent INTEGER, -- d
prime1 INTEGER, -- p
prime2 INTEGER, -- q
exponent1 INTEGER, -- d mod (p-1)
exponent2 INTEGER, -- d mod (q-1)
coefficient INTEGER, -- (inverse of q) mod p
otherPrimeInfos OtherPrimeInfos OPTIONAL
}