从PKS文件中获取python signxml的证书和密钥



我使用以下命令获取cert&从PKS文件中键。

 openssl pkcs12 -in ../my.pfx  -nocerts -out my.key
openssl pkcs12 -in ~/my.pfx -clcerts -nokeys -out cert.pem

但是,我不断出现错误。我怀疑我的key 是不正确的。如何生成正确的密钥和证书来喂食signxml?我在Ubuntu 16.04上使用Python3.5。预先感谢您!

 File "/home/ubuntu/.local/lib/python3.5/site-packages/signxml/__init__.py", line 362, in sign
    key = load_pem_private_key(key, password=passphrase, backend=default_backend())
  File "/home/ubuntu/.local/lib/python3.5/site-packages/cryptography/hazmat/primitives/serialization/base.py", line 16, in load_pem_private_key
    return backend.load_pem_private_key(data, password)
  File "/home/ubuntu/.local/lib/python3.5/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1025, in load_pem_private_key
    password,
  File "/home/ubuntu/.local/lib/python3.5/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1218, in _load_key
    mem_bio = self._bytes_to_bio(data)
  File "/home/ubuntu/.local/lib/python3.5/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 454, in _bytes_to_bio
    data_ptr = self._ffi.from_buffer(data)
TypeError: from_buffer() cannot return the address of a unicode object

XML页面的示例代码:

cert = open("example.pem").read()
key = open("example.key").read()
root = ElementTree.fromstring(data_to_sign)
signed_root = XMLSigner().sign(root, key=key, cert=cert)
verified_data = XMLVerifier().verify(signed_root).signed_xml

我想这是python2 vs python3的东西。我需要的是

key = open("example.key").read().encode('ascii')

相关内容

  • 没有找到相关文章

最新更新