使用OpenSSL 3.0.2工具生成RSA公钥和私钥
  • 1、生成原始RSA用户私钥文件
openssl genrsa -out private_key.pem 1024

这一步生成的样例如下

-----BEGIN PRIVATE KEY-----
MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAL1+xEQSgG1x/+Le
m37aLMEcPYH0QJrJD90tE4DN52cHOsz8TOSyWB7woBl7E+hTlb3GlVb6mk3N0jmL
......
wgkYFQtKjPFUFFk=
-----END PRIVATE KEY-----

如果要生成旧版本的私钥则可增加参数-traditional

openssl genrsa -traditional -out old_private_key.pem 1024

旧版本样式如下

-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQDahyKInSayKqGi2m92LNMk8puttIGesuq9anz2alG53ubUVyPm
C8Ms0GfxO1BsVdRyoI0+IuCqjpETxUUMKbgy8+GGahlGc4IzG8oJ4lxRVrYtykne
......
1UZswocs1Spt9gl7FVm4T6wSeq3c4C3lJcWREwXVNDc=
-----END RSA PRIVATE KEY-----
  • 2、可将原始RSA用户私钥转换为pkcs8格式
openssl pkcs8 -topk8 -inform PEM -in private_key.pem -outform PEM -nocrypt
  • 3、在RSA私钥基础上提取RSA公钥
openssl rsa -in private_key.pem -pubout -out public_key.pem

赞赏(Donation)
微信(Wechat Pay)

donation-wechatpay