I am trying to decrypt a message sent by an app. It uses AES-256 GCM. It sends a JSON in like the following:
text = {"content":"0WKFZaesPEP+nlNqcgiLDMapSsEp","iv":"c46c5cb0f1d016ac225ee82b","tag":"54f77d985b7844030d997508e8b9bcd1"}
Then I am trying to decrypt the data in Python using pycryptodome using AES-256 GCM. I have the following code:
def decrypt(encryptedMsg, secretKey):
authTag = encryptedMsg['tag']
nonce = encryptedMsg['iv']
ciphertext = encryptedMsg['content']
secretKey = base64.b64decode(secretKey)
aesCipher = AES.new(secretKey, AES.MODE_GCM, nonce.encode())
plaintext = aesCipher.decrypt_and_verify(ciphertext.encode(), authTag.encode())
return (plaintext)
I think this is close to working. Please note the secretKey is in base64 so it has to be decoded from base64 to be 32 characters. I am getting an error from this as follows:
raise ValueError("MAC check failed")
ValueError: MAC check failed
I have also tried using "decrypt" rather than "decrypt_and_verify" without the tag and I get an output but it does not make sense to me:
b'}A\xc2\x9c\xdd\xffk\x87\xa0\xa2\xd3\xa0\x8dB\x0f\xde\xb0h)n.\xea\x82C\x9f[s\\'