def get_public_key(key, passphrase=None, asObj=False):
 if isinstance(key, M2Crypto.X509.X509):
  rsa = key.get_pubkey().get_rsa()
  text = ''
 else:
  text = _text_or_file(key)
  text = get_pem_entry(text)
 if text.startswith('-----BEGIN PUBLIC KEY-----'):
  if (not asObj):
   return text
  bio = M2Crypto.BIO.MemoryBuffer()
  bio.write(text)
  rsa = M2Crypto.RSA.load_pub_key_bio(bio)
 bio = M2Crypto.BIO.MemoryBuffer()
 if text.startswith('-----BEGIN CERTIFICATE-----'):
  cert = M2Crypto.X509.load_cert_string(text)
  rsa = cert.get_pubkey().get_rsa()
 if text.startswith('-----BEGIN CERTIFICATE REQUEST-----'):
  csr = M2Crypto.X509.load_request_string(text)
  rsa = csr.get_pubkey().get_rsa()
 if (text.startswith('-----BEGIN PRIVATE KEY-----') or text.startswith('-----BEGIN RSA PRIVATE KEY-----')):
  rsa = M2Crypto.RSA.load_key_string(text, callback=_passphrase_callback(passphrase))
 if asObj:
  evppubkey = M2Crypto.EVP.PKey()
  evppubkey.assign_rsa(rsa)
  return evppubkey
 rsa.save_pub_key_bio(bio)
 return bio.read_all()

def get_public_key ( key , passphrase = None , asObj = False ) : if isinstance ( key , M2Crypto . X509 . X509 ) : rsa = key . get_pubkey ( ) . get_rsa ( ) text = '' else : text = _text_or_file ( key ) text = get_pem_entry ( text ) if text . startswith ( '-----BEGIN PUBLIC KEY-----' ) : if ( not asObj ) : return text bio = M2Crypto . BIO . MemoryBuffer ( ) bio . write ( text ) rsa = M2Crypto . RSA . load_pub_key_bio ( bio ) bio = M2Crypto . BIO . MemoryBuffer ( ) if text . startswith ( '-----BEGIN CERTIFICATE-----' ) : cert = M2Crypto . X509 . load_cert_string ( text ) rsa = cert . get_pubkey ( ) . get_rsa ( ) if text . startswith ( '-----BEGIN CERTIFICATE REQUEST-----' ) : csr = M2Crypto . X509 . load_request_string ( text ) rsa = csr . get_pubkey ( ) . get_rsa ( ) if ( text . startswith ( '-----BEGIN PRIVATE KEY-----' ) or text . startswith ( '-----BEGIN RSA PRIVATE KEY-----' ) ) : rsa = M2Crypto . RSA . load_key_string ( text , callback = _passphrase_callback ( passphrase ) ) if asObj : evppubkey = M2Crypto . EVP . PKey ( ) evppubkey . assign_rsa ( rsa ) return evppubkey rsa . save_pub_key_bio ( bio ) return bio . read_all ( )
create the public key object from a retrieved certificate .