extracting public key from certificate and encrypting data

后端 未结 2 1101
眼角桃花
眼角桃花 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 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)
    

提交回复
热议问题