Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert PKCS#8-formatted PEM private key to the traditional format?

From OpenSSL 1.0 change log:

Make PKCS#8 the default write format for private keys, replacing the traditional format. This form is standardised, more secure and doesn't include an implicit MD5 dependency. [Steve Henson]

However, I need the private key file in the previous, traditional format. Is it possible to convert the pem file from PKCS#8 to the traditional format (using OpenSSL.exe app)?

Thank you very much!

like image 498
rkellerm Avatar asked Jun 02 '10 12:06

rkellerm


People also ask

What is PKCS format?

PKCS#12 (also known as PKCS12 or PFX) is a binary format for storing a certificate chain and private key in a single, encryptable file. PKCS#12 files are commonly used to import and export certificates and private keys on Windows and macOS computers, and usually have the filename extensions . p12 or . pfx .


2 Answers

Succeeded to solve that in that way - the request:

openssl req -configconfigfile.cfg -newkey rsa:2048 -keyout newkey.pem -out newreq.pem 365

Then, I converted it to RSA format:

openssl rsa -in newkey.pem -out newkey.pem

Hope that it will help someone.

like image 140
rkellerm Avatar answered Nov 11 '22 12:11

rkellerm


  1. rsa private key

To convert from PKCS#1 to PKCS#8:

openssl pkcs8 -topk8 -inform pem -in private_pkcs1.pem -outform pem -nocrypt -out private_pkcs8.pem

To convert from PKCS#8 to PKCS#1:

openssl rsa -in private_pkcs8.pem -out private_pkcs1.pem

  1. rsa public key

To convert from PKCS#8 to PKCS#1:

openssl rsa -pubin -in public_pkcs8.pem -RSAPublicKey_out -out public_pkcs1.pem

To convert from PKCS#1 to PKCS#8:

openssl rsa -RSAPublicKey_in -in public_pkcs1.pem -pubout -out public_pkcs8.pem

like image 35
Donghua Liu Avatar answered Nov 11 '22 12:11

Donghua Liu