Python:使用pyOpenSSL.crypto读取pkcs12证书 [英] Python: reading a pkcs12 certificate with pyOpenSSL.crypto

查看:5149
本文介绍了Python:使用pyOpenSSL.crypto读取pkcs12证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由西班牙当局(FNMT)颁发的有效证书,我想使用它来了解更多。
文件扩展名为.p12

I have a valid certificate issued by the spanish authority (FNMT) and I want to play with it to learn more about it. The file has extension .p12

我想读取其中的信息(姓和名),并检查证书是否有效。有可能做到这一点与pyOpenSSL?我想我必须使用OpenSSL中的加密模块。
任何帮助或有用的链接?尝试在此处阅读: http://packages.python.org/pyOpenSSL/openssl-crypto.html ,但没有多少信息: - (

I would like to read the information in it (first and last name) and check if the certificate is valid. Is it possible to do that with pyOpenSSL? I guess I have to use the crypto module in OpenSSL. Any help or useful link? Trying reading here: http://packages.python.org/pyOpenSSL/openssl-crypto.html but not much information :-(

推荐答案

这是相当直接使用。 / p>

It's fairly straight-forward to use. This isn't tested, but should work:

# 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.

有关更多示例,请查看 pyopenssl的单元测试代码

For more examples, have a look through the unit test code of pyopenssl. Pretty much every way you might want to use the library is there

另请参阅此处或无广告此处

这篇关于Python:使用pyOpenSSL.crypto读取pkcs12证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆