My questions are:
- How to create
- a public key
- and a private key with OpenSSL on Windows?
- How to put the created public key
- in a
.crtfile and - the private one in a
.pkcs8file?
- in a
I want to use these two keys to sign a SAML assertion in Java.
You can generate a public-private keypair with the genrsa context (the last number is the keylength in bits):
openssl genrsa -out keypair.pem 2048
To extract the public part, use the rsa context:
openssl rsa -in keypair.pem -pubout -out publickey.crt
Finally, convert the original keypair to PKCS#8 format with the pkcs8 context:
openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in keypair.pem -out pkcs8.key
keypair.pem is identical to pkcs8.key. No need for 3rd command. Just make sure you name your private key what you want in the first command, then run the second command to generate your public key.
.crtfile) contains a public key, but a public key in itself is not a certificatei2d_RSAPrivateKey_bio. An example of writing in all the formats is also given at How to generate RSA private key using OpenSSL?