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
评论列表
文章目录