PyCrypto支持 PKCS#1 ,因为它可以读取X.509
SubjectPublicKeyInfo对象,该对象 包含 以 PKCS#1
编码的RSA公钥。
而是,您密钥中编码的数据是纯
RSAPublicKey对象(即具有两个INTEGER(模数和公用指数)的ASN.1 SEQUENCE)。
您仍然可以阅读它。尝试类似的方法:
from Crypto.PublicKey import RSAfrom Crypto.Util import asn1from base64 import b64deprekey64 = 'MIGJAoGBAJNrHWRFgWLqgzSmLBq2G89exgi/Jk1NWhbFB9gHc9MLORmP3BOCJS9konzT/+Dk1hdZf00JGgZeuJGoXK9PX3CIKQKRQRHpi5e1vmOCrmHN5VMOxGO4d+znJDEbNHODZR4HzsSdpQ9SGMSx7raJJedEIbr0IP6DgnWgiA7R1mUdAgMBAAE='keyDER = b64depre(key64)seq = asn1.DerSequence()seq.depre(keyDER)keyPub = RSA.construct( (seq[0], seq[1]) )
从2.6版开始,PyCrypto还可以导入
RsaPublicKeyASN.1对象。这样的代码就更简单了:
from Crypto.PublicKey import RSAfrom base64 import b64deprekey64 = b'MIGJAoGBAJNrHWRFgWLqgzSmLBq2G89exgi/Jk1NWhbFB9gHc9MLORmP3BOCJS9konzT/+Dk1hdZf00JGgZeuJGoXK9PX3CIKQKRQRHpi5e1vmOCrmHN5VMOxGO4d+znJDEbNHODZR4HzsSdpQ9SGMSx7raJJedEIbr0IP6DgnWgiA7R1mUdAgMBAAE='keyDER = b64depre(key64)keyPub = RSA.importKey(keyDER)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)