使用 python 解密 Amazon SP API 报告文档.AES、CBC、base64 [英] Decrypting Amazon SP API Report Document using python. AES, CBC, base64

查看:24
本文介绍了使用 python 解密 Amazon SP API 报告文档.AES、CBC、base64的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试解密报告文档.我有以下解密细节:

I am trying to decrypt the report document. I have the following details for decryption:

{
"payload": {
    "reportDocumentId": "XXXX",
    "encryptionDetails": {
        "standard": "AES",
        "initializationVector": "XXXX",
        "key": "XXXX"
    },
    "url": "https://XXXXX"
}}

使用这些细节我尝试编写各种代码,给出不同的错误1.

Using these details I tried writing various codes giving different errors 1.

from base64 import b64encode 
import hashlib 
import pyaes 
import os
from sys import getsizeof

content = requests.get(url)
ciphertext = content.text
#ciphertext = b64encode(bytes(content.text))
print(getsizeof(key))
print(getsizeof(iv))
decrypter = pyaes.Decrypter(pyaes.AESModeOfOperationCBC(key, iv)) 
decryptedData = decrypter.feed(ciphertext) 
decryptedData += decrypter.feed()
print(decryptedData)

这显示了以下错误:ValueError:初始化向量必须为 16 字节我的初始化向量和密钥在 base64 中.它们的大小分别为 73 和 93

This shows the following error: ValueError: initialization vector must be 16 bytes My initialization vector and key are in base64. Their size is 73 and 93 respectively

2.

content = requests.get(url)

message = content.text
print(len(message))

obj = AES.new(key, AES.MODE_CBC, iv)
print(obj.decrypt(message))

这会产生以下错误:ValueError:AES 密钥长度不正确(44 字节)

我该如何解决这个问题?除此之外的任何方法也将非常有帮助

How do I solve this issue? Any approach other than this will also be very helpful

AWS KMS 是否有助于解密此类数据?

Does AWS KMS help in decrypting such data?

推荐答案

content = requests.get(url)
message = content.content
dec_key = b64decode(key)
dec_iv = b64decode(iv)
obj = AES.new(dec_key, AES.MODE_CBC, dec_iv)
decrypt_text = obj.decrypt(message)

修改后的代码给出了所需的输出.解码密钥和iv.这个答案不是我的,我是从关于 stackoverflow 的各种问题中收集到的.为任何可能需要它的人编写它.

Modified code gives the desired output. Decode the key and iv. This answer is not by me, I have gathered from various questions on stackoverflow. Writing it for anyone who might need it.

这篇关于使用 python 解密 Amazon SP API 报告文档.AES、CBC、base64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆