I am trying a very basic use case to encrypt and decrypt a sample string. Below is my method. I am using pycryptodome for the encryption.
@staticmethod
def encryptdecrypt(field):
if field is None:
return None
else:
print("Input Text is --> "+field)
cipher = AES.new(CryptHelper.secret_key,AES.MODE_EAX)
text = cipher.encrypt(field.encode('UTF-8'))
print("Encrypted String --> "+str(text))
cipher = AES.new(CryptHelper.secret_key,AES.MODE_EAX)
text = cipher.decrypt(text).decode('cp1252')
print("Decrypted String --> " +text)
I am not able to regenerate the original string. I get gibberish o/ps such as below. I tried with different encodings as I am on Windows 10. But none of the give me the original string. Am I missing something here? Am very new to python. so incase if I am performing a blunder, please do let me know.
Input Text is --> Secret
Encrypted String --> b'^\xb4\xc7A\xbc\x05'
Decrypted String --> >F8Ò³…