Python Aes-256 GMC decript error at decode result

问题描述 投票:0回答:0

我面临将在 Node JS 中加密的数据解密为 python 代码的问题:

Error at "return decrypted.decode('utf-8')"
Error: 'utf-8' codec can't decode byte 0xc8 in position 0: invalid continuation byte

知道为什么吗?

import base64
from Crypto.Cipher import AES

args = {
    "content": "725cd5204cf64987a39a6622884527e0",
    "iv": "e6174b11cd2a18fc",
    "tag": {
        "data": [26, 91, 205, 206, 134, 22, 167, 101, 110, 27, 155, 100, 41, 99, 34, 135],
        "type": "Buffer"
    },
    "key": "SqqUUMnwEVUCBYT7p/0Zfz4Cq2eazHqQ"
}

def decrypt_auth_tag(args):
    try:
        key = args["key"]
        content = bytes.fromhex(args["content"])
        iv = bytes.fromhex(args["iv"])
        tag = bytes(args["tag"]["data"])
        
        cipher = AES.new(key.encode('utf-8'), AES.MODE_GCM, nonce=iv)
        cipher.update(tag)
        decrypted = cipher.decrypt(content)
        return decrypted.decode('utf-8')
    except Exception as e:
        print("Error:", e)

print(decrypt_auth_tag(args))
python encryption aes
© www.soinside.com 2019 - 2024. All rights reserved.