MAC OS下使用OpenSSL生成私钥和公钥的方法

MAC OS自带了OpenSSL,直接在命令行里使用OPENSSL就可以。

打开命令行工具,然后输入 openssl打开openssl,接着只要三句命令就可以搞定。


1、打开Terminal--cd 到指定文件夹MyTestCert

kenMac:~ MyTestCert$openssl


2、OpenSSL后运行> genrsa -out rsa_private_key.pem 2048 // 第一句命令:生成私钥。接下来Terminal显示内容如下:

Generating RSA private key, 2048 bit long modulus

...............+++

..............................................+++

e is 65537 (0x10001)


3、OpenSSL后接着运行> pkcs8 -topk8 -inform PEM -in rsa_private_key.pem -outform PEM –nocrypt // 第二句命令:把RSA私钥转换成PKCS8格式。提示输入密码,密码为空(直接回车)就行;

Enter Encryption Password:

Verifying - Enter Encryption Password:


4、Terminal显示如下:

-----BEGIN ENCRYPTED PRIVATE KEY-----

MIIE6TAbBgkqhkiG9w0BBQMwDgQIiQ4PFYMqa7ECAggABIIEyARDwR3lbjFQYGmy

ASuI2D8LJXOtQDf/BIfFFln6d9UgppOEWlKIrp1ms6BF0nP76mtBiOpsk5QjPhTK

U4snDLT/w/hTc2OBPe66poOtzlVPtKLacfTH1pMzHUWcVz4cmCI+SAMTRkdQ1EG+

UtmdlISxoHqFIuiP4GsuyItVLrqvYMEN+4rMkcO6HgKTInvAVogp05QzJCSOVKCX

6C9Jpgdy+la9rIqteueioYofmgFojZGQtuCh03BgFBD5cHjMWNZ9X9vmxq/ih0ib

NhUptlvwQeaA2OO0pDhOM613b8osGFxvhb14KjMCQdfaYAu9fYw2rFNbZG4Q6BBu

7j+iheHiUdqA/2K9IjTf8kcJGYbQvAlz8GdL/psosk7irBndHEOOZTLgY4xU6t71

Vxwyf9WHbTuuY+MZbzMdo02lKTcznpiT0wdEu+gD5juz5wTVKyZ2HIoT+47Vte6Z

J16X9X1jw3KlIwDl/vFTEBGS1lfn8kMxyuGbomEMlF+If8MXvtY3mfBO5FHSy271

YVRCemxygsUpnMRgRjBdeCAefO8e+vEI2Rh/goCwkq+QmtNnhxMMXdiSn/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-----


5、OpenSSL后运行> rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem // 第三句命令生成公钥。

Terminal显示:

writing RSA key


最后附上截图。



生成的文件:


评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值