Gaurav Sood
Gaurav Sood

Reputation: 690

convert .pem private key to .key format

i have a private key in .pem format. i wish to convert this into .key format. is there any way i can do that?

i am referring to this guide by google on how to generate certificates and private keys for SSO

i have generated the private key using openssl command:

openssl genrsa -out rsaprivkey.pem 1024

what can i do to get the private key in .key format?

Upvotes: 3

Views: 53270

Answers (1)

pepo
pepo

Reputation: 8877

There is no .key format. You can have private (or public) key in PEM or DER encoding. And you can have private key in PKCS#1 or PKCS#8 format. The extensions (.der, .pem, .key, .cer etc.) are only for convenience to easily identify what is inside (well, we wish to trust that the content corresponds to the extension used).

Command openssl genrsa -out rsaprivkey.pem 1024 generated private key in PKCS#1 format and PEM encoding. In the guide you mentioned there are additional steps to take:

openssl rsa -in rsaprivkey.pem -pubout -outform DER -out rsapubkey.der
openssl pkcs8 -topk8 -inform PEM -outform DER -in rsaprivkey.pem -out rsaprivkey.der -nocrypt

Step 1 extracts the public key from rsaprivkey.pem and encodes it in DER format. Step 2 transforms the private key from PKCS#1 to PKCS#8 format (unencrypted) and DER encoding.

The guide also mentions that some Java SSO example expects DSA keys. The keys that you generated using openssl genrsa -out rsaprivkey.pem 1024 are RSA keys.

Upvotes: 16

Related Questions