从远程机器导入 RSA 密钥对

Importing RSA Key Pair from remote Machine

我是 python 的新手,但对加密模块有基本的了解。但是,我正在尝试从远程计算机(即 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)

这就是我打开密钥对的全部内容。我可以将密钥对导入我的个人计算机,这样它就在我有权访问的目录中。

我在别处找到了答案。

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()

这里有一个 link 可以将对象位置转换为 PEM 格式的字符串。 PyOpenSSL convert certificate object to .pem file