利用openSSL 生成RSA公钥和密钥

安装openssl for Windows.

之后开管理员控制台,打开openSSL

我的是

C:\OpenSSL-Win32\bin\openssl.exe

生成1024位的私钥,不指定的话默认2048位

genrsa -out rsa_private_key.pem 1024 

根据这个私钥生成公钥

pkcs8 -topk8 -inform PEM -in rsa_private_key.pem -outform PEM -nocrypt

 

之后用文件名搜索rsa_private_key.pem.这个是私钥

我的win8.1不知道为毛跑到C:\Windows\SysWOW64.

rsa_public_key.pem是公钥.复制分割线内的内容即可

-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQCh/8/kU4Um2FUrkTYXWQDW4MqYuiQQ1WaEtL4JQSy6w64iqWoB
DPcS+BFhaPj8gr1Da+F9Up/s7CSj4Do5h3kMHmRfXu2Ba/Hxczf/QB+Cutm386ro
P41bAKolkUVgWlZEDjOc4+sqrPygxDa0dtbugrdSvJXqUcmJSIkVnVXj0QIDAQAB
AoGAJKmwcwwz5kavf9ytUTtjZT4am9YEs4qYWRBOsel+JgaDMnUE+JfmkvRxeoo3
T26HRurzbVl1uDj5Ud09UCfIzQkmJr1g7AG2Rb1qMGILjz2u5rIve8Q/lwi+nd8e
xNSJ+IYOkoBRCfpUX6ALa/rcBikHeZFS/QMVWNPG8gSXwQECQQDMWV8WHfSLn6CV
Q5Lvg1hVBvFutCZ6BPBNdIi5gQahVsaZ2HH4UlZa8nfiZlojyZiyi9sahwjI0nlg
rbwng61VAkEAyvImDq9akdpVf4JoPMvrRhjYLMMmgWbOhqZyoSU23pOP9OyOW2Fr
dbFXM13QsEGDBCDtrXCrlD8127WxFHG8jQJAMUcsAu1eV307AEO3X0LRPk/aUNPo
o2wldsgvYGyY6LdAVUE42qUgZfYqqtH70r1+sS/AunjtyV/YHVRIF09NsQJBAIJc
/dldBr6+E0GvESpMizsh5msKiIeC9JNGBEhDUXW0MDrSYbeNYqvdWPhkARPXYUOb
q1FIGM9Hs18I3VEWplkCQQC0gZUolARBWozZyhqEyHGW2Tb/ZPZrhNWt0a3yjuqY
EFSOe9WxanF4j2bYAgbGOYyiNHj/IcC4bpUdJeXmTGTz
-----END RSA PRIVATE KEY-----

-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCh/8/kU4Um2FUrkTYXWQDW4MqY
uiQQ1WaEtL4JQSy6w64iqWoBDPcS+BFhaPj8gr1Da+F9Up/s7CSj4Do5h3kMHmRf
Xu2Ba/Hxczf/QB+Cutm386roP41bAKolkUVgWlZEDjOc4+sqrPygxDa0dtbugrdS
vJXqUcmJSIkVnVXj0QIDAQAB
-----END PUBLIC KEY-----

  java生成的密钥的第一步略有不同

OpenSSL> pkcs8 -topk8 -inform PEM -in rsa_private_key.pem -outform PEM -nocrypt

具体看那个open支付宝的链接,嘿嘿.

 

 

参考链接:

http://slproweb.com/products/Win32OpenSSL.html

http://open.alipay.com/platform/document.htm#webApp-intro-safe-intro

 

你可能感兴趣的:(利用openSSL 生成RSA公钥和密钥)