一.创建pkcs8格式的RSA私钥和和公钥
步骤如下:
1.生成 RSA 私钥
openssl genRSA -out RSAprivatekey.pem 1024
2.生成对应的公钥
openssl RSA -in RSAprivatekey.pem -pubout -out RSApublickey.pem
3.将 RSA 私钥转换成 PKCS8 格式,
openssl pkcs8 -topk8 -inform PEM -in RSAprivatekey.pem -outform PEM -nocrypt -out RSAprivatepkcs8.pem
4.生成的RSAprivatepkcs8.pem/RSApublickey.pem 需要提取key文件部分并且将key合并成一行生成新的公钥和私钥, 这对密钥就可以用了.即生成了后缀名为pem格式的Rsa密钥.
$ cat merge.py
import sys
fname = sys.argv[1]
f=open(fname)
total=”
for l in f.readlines():
if l.startswith(‘—-‘):
continue
total = total + l.strip()
print(total)
二.创建pkcs12格式的RSA证书
今天生成pkcs12格式的RSA密钥老出问题,在把公钥和私钥合并生成.p12证书的时候,一直出错提示
unable to load certificates,后来重新找生成2048 bit的就没有问题了,之前生成的都是1024 bit的.生成过程很
简单.
具体步骤如下:
1.运行以下OpenSSL命令生成私钥和公钥证书(运行以下OpenSSL命令生成私钥和公共证书)
(certificate.pem为公钥,key.pem为私钥)
openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 365 -out certificate.pem
2.查看自己创建的公钥证书
openssl x509 -text -noout -in certificate.pem
3.合并公钥和私钥生成PKCS 12证书:
openssl pkcs12 -inkey key.pem -in certificate.pem -export -out certificate.p12
4.校验PKCS 12证书密码
openssl pkcs12 -in certificate.p12 -noout -info
到此PKCS 12证书文件就生成好了,直接在windows下双击输入密码进行导入后,就可以在爱IE浏览器下的证书下面看见了.例如:
3.获取pem后缀私钥:
openssl pkcs12 -in yourP12File -nocerts -out privateKey.pem
查阅:
https://www.ibm.com/support/knowledgecenter/en/SSWHYP_4.0.0/com.ibm.apimgmt.cmc.doc/task_apionprem_gernerate_self_signed_openSSL.html
相关资源:KeePass秘钥管理软件安装使用说明.docx-其它工具类资源-CSDN文库
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!