《RSA公私鑰生成和RSA證書創建”利器”》要點:
本文介紹了RSA公私鑰生成和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.pyimport 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密鑰老出問題,在把公鑰和私鑰合并生成.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瀏覽器下的證書下面看見了.例如:
1.獲取pem后綴公鑰:
openssl pkcs12 -in yourP12File ?-clcerts -nokeys -out publicCert.pem
2.先把p12證書安裝導入到IE瀏覽器下,再從IE中導出公鑰.支持的格式有CER,P7B格式.
獲取pem后綴私鑰:
openssl pkcs12 -in yourP12File ?-nocerts -out privateKey.pem
文章來自微信公眾號:Python運維圈
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/2194.html