来源:https://www.upsync.dev/2022/02/22/loading-a-rsa-private-key
Converting PKCS#1 RSA key to PKCS#8 format
- 生成 PKCS#1 格式的 RSA 秘钥文件
openssl genrsa -f4 -out rsa.key 2048
或者使用 python
代码生成(pip install rsa -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
)
import rsa
(pubkey, privkey) = rsa.newkeys(512) #
bindata = privkey.save_pkcs1()
with open(rsa.key, 'wb') as f:
f.write(bindata)
- Convert the rsa.key to PKCS#8 format
openssl pkcs8 -topk8 -inform PEM -outform DER -nocrypt -in rsa.key -out rsa.key.der
此时 rsa.key.der
是二进制数据格式
- 转换为 PEM 格式
openssl rsa -in rsa.key.der -inform DER