def get_public_key(private_key): if not isinstance(private_key, crypto.PKey): private_key = crypto.load_privatekey(crypto.FILETYPE_PEM, private_key) bio = crypto._new_mem_buf() cryptolib.PEM_write_bio_PUBKEY(bio, private_key._pkey) public_key = crypto._bio_to_string(bio) return public_key
def cert_public_key(self) -> GreppedOut: """ Get the public key from CERT.RSA Returns ------- GreppedOut : object GreppedOut object Examples -------- >>> from glorifiedgrep import GlorifiedAndroid >>> a = GlorifiedAndroid('/path/to/apk') >>> a.cert_public_key() """ pkcs7 = crypto.load_pkcs7_data(crypto.FILETYPE_ASN1, self._read_cert()) certs = self._get_certificates(pkcs7) p = certs[0].get_pubkey() bio = crypto._new_mem_buf() cryptolib.PEM_write_bio_PUBKEY(bio, p._pkey) key = crypto._bio_to_string(bio) self._cert_analysis['public_key'] = [key] self.log_debug('') return GreppedOut([key])
def pem_publickey(pkey): """ Format a public key as a PEM. From https://stackoverflow.com/a/30929459/1827854""" bio = crypto._new_mem_buf() cryptolib.PEM_write_bio_PUBKEY(bio, pkey._pkey) return crypto._bio_to_string(bio)
if email: formatted_res += "Subject Owner email is: " + email.decode('utf-8') + '\n' #################### # Get cert version # #################### cert_ver = reqObj.get_version() formatted_res += "\nCertificate Version number: " + str(cert_ver) + '\n' ################################ # Format a public key as a PEM # ################################ bio = crypto._new_mem_buf() cryptolib.PEM_write_bio_PUBKEY(bio, reqObj.get_pubkey()._pkey) pubkey = crypto._bio_to_string(bio) pubkey_size = reqObj.get_pubkey().bits() formatted_res += "\nPublic key size: " + str(pubkey_size) + '\n' formatted_res += "Public key:\n\n" + pubkey.decode('utf-8') + '\n' ######################################################### # Get all extensions of the certificate in list of dict # ######################################################### formatted_res += "\nCertificate extensions list:\n" extensions = {} X509exts = reqObj.get_extensions()
def pem_publickey(pkey): """ Format a public key as a PEM """ bio = crypto._new_mem_buf() cryptolib.PEM_write_bio_PUBKEY(bio, pkey._pkey) return crypto._bio_to_string(bio)
def Get_PublicKey_String_from_KeyPair(pkey): """ Format a public key as a PEM """ bio = crypto._new_mem_buf() cryptolib.PEM_write_bio_PUBKEY(bio, pkey._pkey) return crypto._bio_to_string(bio)