extracting public key from certificate and encrypting data

后端 未结 2 1091
眼角桃花
眼角桃花 2020-12-17 06:32

This is for a homework assignment! I get the server\'s certificate using get_peer_certificate() and the calling dump_certificate to dump the certif

相关标签:
2条回答
  • 2020-12-17 06:38
        crtObj = crypto.load_certificate(crypto.FILETYPE_ASN1, config.x509_certificate)
        pubKeyObject = crtObj.get_pubkey()
        pubKeyString = crypto.dump_publickey(crypto.FILETYPE_PEM, pubKeyObject)
    
    0 讨论(0)
  • 2020-12-17 07:01

    I'd recommend using a more broad crypto library such as M2Crypto which has the X509 certificate functions as well as RSA encryption:

    from M2Crypto import RSA, X509
    data = ssl_sock.getpeercert(1)
    # load the certificate into M2Crypto to manipulate it
    cert = X509.load_cert_string(data, X509.FORMAT_DER)
    pub_key = cert.get_pubkey()
    rsa_key = pub_key.get_rsa()
    cipher = rsa_key.public_encrypt('plaintext', RSA.pkcs1_padding)
    
    0 讨论(0)
提交回复
热议问题