English 中文(简体)
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!

最佳回答

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.

问题回答

Using Openssl 3.0 :https://www.openssl.org/docs/man3.0/man1/openssl-pkey.html

Convert from PKCS#1 to PKCS#8:

$ cat pkcs1.pem
-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----
$ openssl pkey -in pkcs1.pem
-----BEGIN PRIVATE KEY-----
...
-----END PRIVATE KEY-----

Convert from PKCS#8 to PKCS#1:

$ cat pkcs8.pem
-----BEGIN PRIVATE KEY-----
...
-----END PRIVATE KEY-----
$ openssl pkey -in pkcs8.pem -traditional
-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----

See https://stackoverflow.com/a/20065522/2162144 for a description of PKCS#1 vs PKCS#8.

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

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




相关问题
SSL wrapper stream in C

I have a simple stream_t type in C with your basic read/write operations, and support for multiple underlying implementations using function pointers. So a stream could be backed by a file, a char ...

Access violation writing location

I have the following code: #include <openssl/bn.h> #include <openssl/rsa.h> unsigned char* key; RSA* rsa = RSA_new(); rsa = RSA_generate_key(1024,65537,NULL,NULL); //init pubkey key[...

Visual Studio merging DLL into console application

I have very simple program to simplify things as shown below... #include <openssl/evp.h> int main (int argc, char *argv[]) { EVP_CIPHER_CTX ctx; EVP_CIPHER_CTX_init(&ctx); } ...

Can t add static lib

I am trying to build a DLL and it needs to reference a library namely libeay32.dll from the openssl package. I cant seem to add it as a reference under the Property Pages->Common Properties->Add New ...

Php paypalewp on windows not working right, short return

I am working on a payment script using paypalewp, it seems to work fine in the stage environment which is a centos linux box, however on my dev box it doesn t... when I run the button creation ...

How do I get SSL working in fsockopen?

I m running PHP 5.2.6 on Windows, I have extension=php_curl.dll and extension=php_openssl.dll uncommented in php.ini; as such I can see the following in phpinfo: curl cURL support enabled cURL ...

Load RSA keys from files

I used openSSL command to create 2 files: 1 for RSA public key & 1 for RSA private key. How do I recover RSA keys using C? Specifically, I have these functions: RSA_public_encrypt(read_num, ...

OpenSSL on iPhone

I need to figure out how to get two OpenSSL functions for iPhone. I m trying to keep it so I don t need another dylib, because I don t want Apple to reject my application for something so silly. ...

热门标签