从远程计算机导入RSA密钥对

时间:2016-06-09 13:25:47

标签: python-3.x import rsa

我对python很新,但对crypto模块有基本的了解。但是,我尝试从远程计算机(即Safenet)导入RSA密钥对,以对签名数据运行一些性能测试。我在Python中构建框架,但我还没有找到很多明显的例子。例如:

from Crypto.PublicKey import RSA
f = open('path/to/pair/00000103000003A2','r')
r = RSA.importKey(f.read(),  passphrase='123456') # Index out of range error
print(r)

这就是我打开密钥对时的情况。我可以将密钥对导入我的个人计算机,因此它位于我可以访问的目录中。

1 个答案:

答案 0 :(得分:0)

我在其他地方找到了答案。

from OpenSSL import crypto

passwd = 'The password of your created .p12 file'
p12 = crypto.load_pkcs12(open("Path to p12 file.p12 ",'rb').read(),passwd)
print(p12.get_certificate())    #Prints object location
print(p12.get_privatekey())     #Prints object location
p12.get_ca_certificates()

这是一个将对象位置转换为PEM格式字符串的链接。 PyOpenSSL convert certificate object to .pem file