Below is my code:
from base64 import b64encode, b64decode
from pathlib import Path
from Crypto.Cipher import AES
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_v1_5
def decrypt(base64_ciphertext):
private_key = RSA.import_key(open('fkey.key').read())
ciphertext = b64decode(base64_ciphertext)
cipher_rsa = PKCS1_v1_5.new(private_key)
data = cipher_rsa.decrypt(ast.literal_eval(str(ciphertext)),'Error occured')
return data
The value returned is Error occurred
every time I run this function. Please help. I have confirmed that the ciphertext
being passed is a byte string by logging it. Is there any way to log the actual error due to which decrypt fails instead of returning the sentinel value.
EDIT: It was a mistake from the company providing the API, they changed our credentials and did not inform us, sorry for the trouble and thanks for the help.