def fromPEM_PublicKey(self, publicKeyData): try: key64 = '' for line in publicKeyData.splitlines(): if line.count('BEGIN RSA PUBLIC KEY') or line.count('END RSA PUBLIC KEY'): continue key64 += line.strip() pubSeq = DerSequence() pubSeq.decode(b64decode(key64)) self.key = RSA.construct( (pubSeq[0], pubSeq[1]) ) except: raise RSAError, 'unable to load object from data'
def fromPKey_PublicKey(self, pkey): src = dump_privatekey(FILETYPE_ASN1, pkey) pub_der = DerSequence() pub_der.decode(src) self.key = RSA.construct((long(pub_der._seq[1]), long(pub_der._seq[2])))