本帖最后由 Zhili.An 于 2024-3-26 12:09 编辑
工作需要,有一本书的pdf被加密了。我逆向发现,是对pdf读取base64,再进行AES解密就好,但是在python那里解密一直出错;
不知道什么原因。如果对python中的解密函数直接赋值(指就直接输入较短的加密后的值),是可以解密的。代码如下:
python代码1[Python] 纯文本查看 复制代码 import base64from Crypto.Cipher import AES
def unpad(s):
return s[:-ord(s[len(s)-1])]
def decrypt(message, key):
aes = AES.new(key.encode(), AES.MODE_ECB)
message=aes.decrypt(base64.b64decode(message)).decode()
return unpad(message)
key='F79%AKdcDMSixiz4'
# 读取文件并编码为base64格式
with open("10.pdf", "rb") as file:
encoded = base64.b64encode(file.read())
decrypt(encoded, key)
会报错
[Python] 纯文本查看 复制代码 Traceback (most recent call last):
File "D:\Users\lll\Desktop\jiaoxi\kezhi2.py", line 20, in <module>
decrypt(encoded, key)
File "D:\Users\lll\Desktop\jiaoxi\kezhi2.py", line 11, in decrypt
message=aes.decrypt(base64.b64decode(message)).decode()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc7 in position 10: invalid continuation byte
后面我就直接把这个base64复制到网站【https://www.toolhelper.cn】中,他是可以解密的,但是得到pdf是空白的
python2:
[Python] 纯文本查看 复制代码 import requests
import json
import base64
import PyPDF2
key='F79%AKdcDMSixiz4'
# 读取文件并编码为base64格式
with open("10.pdf", "rb") as file:
encoded = base64.b64encode(file.read())
url = "https://www.toolhelper.cn/SymmetricEncryption/AesDecrypt?gts=1711345342000&gv=638469004576249239&r_=0.2978800889153248"
data = {
"cipherMode": 2,
"paddingMode": 2,
"blockSize": 128,
"keyFormat": 1,
"key": "F79%AKdcDMSixiz4",
"ivFormat": 1,
"iv": "1234567891234567",
"associatedDataFormat": 1,
"associatedData": "",
"encoding": "UTF-8",
"outputFormat": 1,
"dest": encoded.decode()
}
response = requests.post(url, data=data)
response_text = response.text
data_dict = json.loads(response_text)
data = data_dict["Data"]
pdf_file = open("00.pdf", "wb")
# 写入原始数据
pdf_file.write(data.encode())
# 关闭文件
pdf_file.close()
文件地址【链接:https://pan.baidu.com/s/1SaTJhPKrzn6O6z1bj6PcsA?pwd=l3if
提取码:l3if】
希望大佬们一起帮助一下的啦。 |