python等级证书查询_如何检查Python,与证书相关联的密钥或n

OpenSSL库有一个Python接口:pyOpenSSL当前版本为0.13.1。在

编辑:问题的答案。。。在

验证私钥是否与PyOpenSSL的证书匹配:import OpenSSL.crypto

from Crypto.Util import asn1

c=OpenSSL.crypto

# The certificate - an X509 object

cert=...

# The private key - a PKey object

priv=...

pub=cert.get_pubkey()

# Only works for RSA (I think)

if pub.type()!=c.TYPE_RSA or priv.type()!=c.TYPE_RSA:

raise Exception('Can only handle RSA keys')

# This seems to work with public as well

pub_asn1=c.dump_privatekey(c.FILETYPE_ASN1, pub)

priv_asn1=c.dump_privatekey(c.FILETYPE_ASN1, priv)

# Decode DER

pub_der=asn1.DerSequence()

pub_der.decode(pub_asn1)

priv_der=asn1.DerSequence()

priv_der.decode(priv_asn1)

# Get the modulus

pub_modulus=pub_der[1]

priv_modulus=priv_der[1]

if pub_modulus==priv_modulus:

print('Match')

else:

print('Oops')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值