我有西类牙当局 (FNMT) 颁发的有效证书,我想使用它来了解更多信息。 该文件的扩展名为 .p12
我想阅读其中的信息(名字和姓氏)并检查证书是否有效。是否可以使用 pyOpenSSL 做到这一点?我想我必须在 OpenSSL 中使用加密模块。 任何帮助或有用的链接?在这里尝试阅读:http://packages.python.org/pyOpenSSL/openssl-crypto.html但信息不多:-(
最佳答案
使用起来相当简单。这没有经过测试,但应该可以工作:
# load OpenSSL.crypto
from OpenSSL import crypto
# open it, using password. Supply/read your own from stdin.
p12 = crypto.load_pkcs12(open("/path/to/cert.p12", 'rb').read(), passwd)
# get various properties of said file.
# note these are PyOpenSSL objects, not strings although you
# can convert them to PEM-encoded strings.
p12.get_certificate() # (signed) certificate object
p12.get_privatekey() # private key.
p12.get_ca_certificates() # ca chain.
有关更多示例,请查看 unit test code of pyopenssl .几乎所有您可能想要使用该库的方式都在那里
关于Python:使用 pyOpenSSL.crypto 读取 pkcs12 证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6345786/