最近要在新项目中使用支付宝钱包进行支付,所以要调研对接支付宝的接口,支付宝开放平台采用了RSA安全签名机制,开发者可以通过支付宝 公钥验证消息来源,同时可使用自己的私钥对信息进行加密,所以需要在本机上生成私钥和公钥 ...
由此需要开发者在本地上使用openssl来生成私钥和公钥
由于mac 自带openssl工具,所以不用像windows那样要下载安装openssl工具
生成私钥公钥很简单:只要三句命令就可以搞定
打开openssl : $openssl =====>> OpenSSL>
- genrsa -out rsa_private_key.pem 1024 ======>> Generating RSA private key, 1024 bit long modulus
..++++++
.............++++++
e is 65537 (0x10001)
- pkcs8 -topk8 -inform PEM -in rsa_private_key.pem -outform PEM –nocrypt =======>>
Enter Encryption Password:
Verifying - Enter Encryption Password:
-----BEGIN ENCRYPTED PRIVATE KEY-----
MIICoTAbBgkqhkiG9w0BBQMwDgQIB70ErSHm8nACAggABIICgGohYKWaKTEkOJlf
4Lg0rZbnVnCZY2gyFPtu2mEJskQLvtjJWvgqyIGwZG+CcDjurvIhrSH
Q4yz3qOcaywahh6DmXZ1yw+GVyPSiIXC295mnoZo6OIwBu46V5OEPTTpTFLeVpgs
XTAvUN2LXhSXO9TuZKrZG0jujgif/5rT8OcUPV4yrGke0k
KZe9rB0gbaCPxy1GTa3+d6jPX8XqcVRGdsr4YChv2GMpn9XPicD+itbm5/0gqNLk
RwJJ5r4UZCuANXcV8rsE60qi5wlYWdmFu9Mh3UsKER9NzuJPYz/CXXG
OvlU0Gp3s2FfIJwS6lnTJD0PGbgpp+bv1Nyp9R1JH+UgcIKz
4Y6A+np8kVs0uBAN6iGHwEFKq9E73pPEnG
5kBt6OH6kBXPqsnH7h6mdMUxLsqMFG8unjXQr+zovBodDbXjCv6nUpu8+O7pOBI/
z/mczL5auVW+CJBqJPXeqeuw400zi66SJ7a5SDRfiXYJyyT2I3wl9GdAbAdgoChx
tsY61csyWrhIRTdNdbJ7Zck9N2ZgQFOeAPlyiJAYPM3eMUPVkRuXsTLESaKJV8sS
zUyhKeXsO/EdM7HfIDY+GJouJEoNlU2nW2omR9OiFLELgGX4g6afxg5uIx95Xc8J
Gv7xsgtScS7IKzdSaHcUuidPvhMgm3GLEKsLKy9Lz7wN6sTYAPIQPq8/767c2WZA
7RIFGZTOQLWpUNPfdC8mTStPK3F8SPBVGh5KIBl++
nBsTLpc=
-----END ENCRYPTED PRIVATE KEY-----
- rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem =======>>>> writing RSA key
退出openssl: $exit
生成的文件: