安装及更新
mac自带OpenSSL
#确认已安装的openssl的版本和位置
which openssl
#确定版本
openssl version
#brew安装openssl
brew install openssl
#brew更新openssl
brew upgrade openssl
#brew强制链接到openssl
brew link openssl --force
生成私钥公钥
cd /Users/hawkii/IdeaProjects/tensquare_parent03/tensquare_encrypt/src/main/java/com/tensquare/encrypt/rsa
#生成公钥和私钥
(base) Hawkiis-MacBook-Pro:rsa hawkii$ openssl
OpenSSL> genrsa -out rsa_private_key.pem 2048
Generating RSA private key, 2048 bit long modulus (2 primes)
...................................................................................+++++
......................................................................................................................+++++
e is 65537 (0x010001)
OpenSSL> openssl rsa -in ../mycerts/rsa_private_key.pem -pubout -out ../mycerts/rsa_public_key_2048.
Invalid command 'openssl'; type "help" for a list.
error in openssl
OpenSSL> rsa -in ./rsa_private_key.pem -pubout -out ./rsa_public_key_2048.pub
writing RSA key
#生成私钥转化成pkcs8格式
pkcs8 -topk8 -inform PEM -in rsa_private_key.pem -outform PEM -nocrypt -out rsa_private_key_pkcs8.pem