Python: reading a pkcs12 certificate with pyOpenSSL.crypto(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 :-(
推荐答案
使用起来相当简单.这没有经过测试,但应该可以工作:
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 证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Python:使用 pyOpenSSL.crypto 读取 pkcs12 证书
基础教程推荐
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 包装空间模型 2022-01-01
- 求两个直方图的卷积 2022-01-01
