rsa 私钥为什么 转换 pkcs8?
首先配置OPENSSL环境,
windows:
1、下载openssl地址
http://www.openssl.org/source/ 或
http://freefr.dl.sourceforge.net/project/gnuwin32/openssl/0.9.8h-1/openssl-0.9.8h-1-bin.zip
mac:
1、如果没有装可以使用brew install openssl 或下载源码编译(具体可以去百)
2、下载解压到 c:\openssl\下,配置环境变量,把c:\openssl\bin加入到环境变量PATH里(mac 加入到/etc/profile里,记得source下)
3、打开命令行输入 openssl,出现如下界面,说明正确配置好了
C:\Users\Yt>openssl OpenSSL> ? openssl:Error: '?' is an invalid command. Standard commands asn1parse ca ciphers crl crl2pkcs7 dgst dh dhparam dsa dsaparam ec ecparam enc engine errstr gendh gendsa genrsa nseq ocsp passwd pkcs12 pkcs7 pkcs8 prime rand req rsa rsautl s_client s_server s_time sess_id smime speed spkac verify version x509 Message Digest commands (see the `dgst' command for more details) md2 md4 md5 rmd160 sha sha1 Cipher commands (see the `enc' command for more details) aes-128-cbc aes-128-ecb aes-192-cbc aes-192-ecb aes-256-cbc aes-256-ecb base64 bf bf-cbc bf-cfb bf-ecb bf-ofb cast cast-cbc cast5-cbc cast5-cfb cast5-ecb cast5-ofb des des-cbc des-cfb des-ecb des-ede des-ede-cbc des-ede-cfb des-ede-ofb des-ede3 des-ede3-cbc des-ede3-cfb des-ede3-ofb des-ofb des3 desx idea idea-cbc idea-cfb idea-ecb idea-ofb rc2 rc2-40-cbc rc2-64-cbc rc2-cbc rc2-cfb rc2-ecb rc2-ofb rc4 rc4-40 OpenSSL>
4、生成pem格式的私钥:
openssl genrsa -out private_test.key 1024
5、生成公钥:
openssl rsa -in private_test.key -pubout -out public_key.pem
产生的密钥是这样子头尾RSA PRIVATE KEY
-----BEGIN RSA PRIVATE KEY----- 这里是密钥内容 -----END RSA PRIVATE KEY-----
6、转换为公钥
openssl rsa -in private_test_key.pem -pubout -out public_test_key.pem
产生的公钥格式是:
-----BEGIN PUBLIC KEY----- 这里是公钥内容 -----END PUBLIC KEY-----
7、将公钥转换为pkcs8格式
openssl pkcs8 -topk8 -inform PEM -in private_test_key.pem -outform PEM -nocrypt -out private_test_key_pkcs8.pem