Python 从证书中获取主题密钥标识符
是否可以使用python从现有证书中提取 我试过这样的方法:Python 从证书中获取主题密钥标识符,python,cryptography,certificate,pyopenssl,Python,Cryptography,Certificate,Pyopenssl,是否可以使用python从现有证书中提取 我试过这样的方法: from OpenSSL.crypto import load_certificate, FILETYPE_PEM cert_string='-----BEGIN CERTIFICATE--...' certificate=load_certificate(FILETYPE_PEM, plain_cert) subject=certificate.get_subject() 但它给出了证书的主题。证书对象似乎不提供主题密钥标识符的
from OpenSSL.crypto import load_certificate, FILETYPE_PEM
cert_string='-----BEGIN CERTIFICATE--...'
certificate=load_certificate(FILETYPE_PEM, plain_cert)
subject=certificate.get_subject()
但它给出了证书的主题。证书对象似乎不提供主题密钥标识符的函数。还有其他选择吗
subject=certificate.get_extension(0)
完成了任务。与
certificate.get_extension_count()
您可以检查证书有多少扩展名
完成了任务。与
certificate.get_extension_count()
您可以检查证书有多少扩展名。将提取使用者密钥标识符的代码:
from cryptography import x509
from cryptography.hazmat.backends import default_backend
cert = x509.load_pem_x509_certificate(pem_data, default_backend())
ski = cert.extensions.get_extension_for_oid(x509.oid.ExtensionOID.SUBJECT_KEY_IDENTIFIER)
print(ski.value.digest)
将提取主题密钥标识符的代码:
from cryptography import x509
from cryptography.hazmat.backends import default_backend
cert = x509.load_pem_x509_certificate(pem_data, default_backend())
ski = cert.extensions.get_extension_for_oid(x509.oid.ExtensionOID.SUBJECT_KEY_IDENTIFIER)
print(ski.value.digest)