rsa.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:Cryptical 作者: mathieudev 项目源码 文件源码
def rsa_decrypt(priv_key, rsa_ciphertext):
    """Decrypt the RSA ciphertext.

    This function decrypt the ciphertext using RSA-OAEP algorithm and private
    key of the recipient.

    :parameter:
     priv_key : RSA key object
        The RSA private key used to decrypt.
     rsa_ciphertext : string
        Ciphertext to decrypt.

    :return: A string, the plaintext after decryption.
    """

    try:
        # create PKCS1 OAEP cipher to perform decryption
        cipherer = PKCS1_OAEP.new(priv_key)
        # decode then decrypt the ciphertext
        rsa_plaintext = cipherer.decrypt(b64decode(rsa_ciphertext))
    except (ValueError, TypeError):
        print("[error] RSA decryption failed")
        return False

    return rsa_plaintext
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号