Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create PKCS#1 formatted RSA key using OpenSSL v3.0.0

Tags:

openssl

pkcs#1

I wanted to confirm if we can create PKCS#1/traditional formatted RSA keys using version 3.0.0 of OpenSSL. I guess following command is giving me the output in PKCS#8 format. openssl genrsa -out server.key 2048

Thanks.

like image 400
Owais Shahzad Avatar asked Oct 20 '25 04:10

Owais Shahzad


2 Answers

Using OpenSSL 3.0, you can use the -traditional switch to get the older format for your output, both for the openssl rsa and openssl genrsa subcommands. Tested on Ubuntu 22.04.

like image 101
Simon Chopin Avatar answered Oct 24 '25 21:10

Simon Chopin


You can do this directly(PKCS#8):

openssl genpkey -out rsakey.pem -algorithm RSA -pkeyopt rsa_keygen_bits:2048
cat rsakey.pem 
-----BEGIN PRIVATE KEY-----
base64_encode xxx
-----END PRIVATE KEY-----

openSSL 1.1.1(PKCS#1)

openssl genrsa -out server.key 2048

cat server.key 

-----BEGIN RSA PRIVATE KEY-----
base64_encode xxx
-----END RSA PRIVATE KEY-----

openssl pkcs8 to pkcs1 command

openssl rsa -in rsakey.pem -out rsakey_pkcs1.pem
cat rsakey_pkcs1.pem
-----BEGIN RSA PRIVATE KEY-----
base64_encode xxx
-----END RSA PRIVATE KEY-----
like image 38
he shouyong Avatar answered Oct 24 '25 19:10

he shouyong