openssl mac中使用终端生成RSA私钥和公钥文件

时间:2022-05-13 18:03:53

RSA密钥生成命令
生成RSA私钥
openssl>genrsa -out rsa_private_key.pem 1024
生成RSA公钥
openssl>rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem
将RSA私钥转换成PKCS8格式
openssl>pkcs8 -topk8 -inform PEM -in rsa_private_key.pem -outform PEM -nocrypt

注意:“>”符号后面的才是需要输入的命令。

生成公钥和私钥文件的命令

cjh:~ hedawei$ 
cjh:~ hedawei$ openssl
OpenSSL> genrsa -out rsa_private_key.pem 1024
Generating RSA private key, 1024 bit long modulus
........................................................++++++
...............++++++
e is 65537 (0x10001)
OpenSSL> pkcs8 -topk8 -inform PEM -in rsa_private_key.pem -outform PEM -nocrypt
-----BEGIN PRIVATE KEY-----
MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBALpltDmpBGCvVLuC
VKkoM1JSz8QOI2cuAO0P/MdGYPREpXAdOVq3uVCh2MpyOuGenBmhjYJ9BXhgV5tW
0AXPkKl7JrHPWJqEyo8mm9qzIWeGuBZrBpFijOBRM6fTF9SeJ3Cs1GiejAQCrL2T
o9JwzpWU7jCLRKbKc1yEI1dxxfohAgMBAAECgYAowbhIq1ZTtcK3RWYxnqKqK4VW
fyjqlLqLG2XQROlKQABUpW83ENkqclku2w9Y6g+D4zlIAQJDMf2176OIwbwFk2EN
YtF0gBkkgHxYpvBOd7mOmMoUx7qzEA5MsLB9FzmHIPWlm99AUfPSm9UJ7LzRjZPF
uDByPkYXr801hmItiQJBAOCcpbDnVqnNzaGv+gZJVCdyhe8d0ZEsjSq+tnbftjO4
8XxIjxvudCK56VEaXf+gTNAL1KW7qkbbd6TvUvelBesCQQDUcfPA/tYjj056S27a
xlQvNyjmFZjgWypnx//91lTxlZQL+z5Gd8HNgnyD2zUrbI4cyko/P44ZCvFhBvmW
QMEjAkBTRL+IXbsbKFjbYEnomrbACQzuILfYghOzjRBH8ZeyhRXBZYTobfZQCWwd
zRCb++l+F2S2LGRr8GDinHa9qEgRAkA4DCAsyI6iLwqbRQ9n9G79TeYiXYxJlIOp
gaBNzZ/3ZGj8iDozySB+IXDMMKbkX+1WNyBDc3b/sF1iJb7vHwJVAkAP23fyuEpv
Zt/LkdwXl5jwrkLR+zbFtnYt7nmGn1St6PghbdnnJOleLg7faWuHvr5ulzKuIrB3
WYbSa83n/mjo
-----END PRIVATE KEY-----
OpenSSL> rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem
writing RSA key
OpenSSL>

公钥私钥文件可以使用记事本打开查看私钥和公钥的字符串