Python:X509证书的Issuer CN值存储为字符串
问题说明
我正在使用以下代码:
from cryptography import x509
from cryptography.hazmat.backends import default_backend
cert_info = x509.load_pem_x509_certificate(cert_pem, default_backend())
cert_issuer = cert_info.issuer
在PyCharm中调试时,我看到cert_issuer变量如下:
While debugging in PyCharm, I saw that the cert_issuer variable is as following:
我想将commonName值存储在变量中.(上面突出显示的值)
I want to store the commonName value in a variable. (value highlighted above)
我对Python还是很陌生,无法使用这些类型的变量查找任何内容,有人可以指导我将值存储在变量中的语法是什么.
I'm still fairly new to Python and was not able to find anything with these type of variables, can someone please guide me as to what should be the syntax to store that value in a variable.
正确答案
发行人的通用名称(CN)可以如下确定:
The Common Name (CN) of the issuer can be determined as follows:
...
from cryptography.x509.oid import NameOID
cn = cert_info.issuer.get_attributes_for_oid(NameOID.COMMON_NAME)[0].value
...
<代码> cryptography.x509.Certificate#issuer 返回 cryptography.x509.Name
对象,其中包含属性列表.可以使用 来访问此列表的特定属性.get_attributes_for_oid(oid)
,其中必须使用来自 COMMON_NAME
. get_attributes_for_oid(oid)
返回的列表 cryptography.x509.NameAttributes
对象.由于只有一个 Issuer ,因此必须使用第一个 NameAttribute
对象,可以使用查看全文
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcfkhck
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20