【问题标题】:Importing RSA Key Pair from remote Machine从远程机器导入 RSA 密钥对
【发布时间】:2016-06-09 13:25:46
【问题描述】:

我对 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)

这大约是我打开密钥对所得到的。我可以将密钥对导入我的个人计算机,因此它位于我可以访问的目录中。

【问题讨论】:

  • 你能显示一个示例键吗?
  • 这将是我的密钥库的路径。 C:\Users\Name\Company\00000103000003A2.p12@Artjom B
  • PKCS#12 不受 pycrypto 支持。你必须先转换它
  • 是否需要在命令行或 python 代码中使用 openssh 进行转换? python支持什么版本的pkcs?
  • 由于 pyCrypto 不支持 PKCS#12,你不能使用它。所以你必须找到其他方法或使用不同的库。虽然,pyCrypto 支持 OpenSSH 文件格式,但我不确定它是否仅适用于公钥或私钥。

标签: python-3.x import rsa


【解决方案1】:

我在别处找到了答案。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-20
    • 1970-01-01
    • 1970-01-01
    • 2017-10-18
    • 1970-01-01
    • 1970-01-01
    • 2010-10-21
    • 1970-01-01
    相关资源
    最近更新 更多