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 证书
基础教程推荐
- 尝试制作WhatsApp机器人 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
