python - AES 密钥,解密器 = AES.new(HEADER_KEY, AES.MODE_CBC, 16 * '\x00')
问题描述
尝试从 2017 年开始运行此代码 - https://gist.github.com/dfirfpi/2602b726af1b944efa723d34b624ad88
Traceback (most recent call last):
File "C:\unssz.py", line 58, in <module>
main()
File "C:\unssz.py", line 34, in main
decryptor = AES.new(HEADER_KEY, AES.MODE_CBC, 16 * '\x00')
File "C:\Users\artur\AppData\Local\Programs\Python\Python39\lib\site-packages\Crypto\Cipher\AES.py", line 232, in new
return _create_cipher(sys.modules[__name__], key, mode, *args, **kwargs)
File "C:\Users\artur\AppData\Local\Programs\Python\Python39\lib\site-packages\Crypto\Cipher\__init__.py", line 79, in _create_cipher
return modes[mode](factory, **kwargs)
File "C:\Users\artur\AppData\Local\Programs\Python\Python39\lib\site-packages\Crypto\Cipher\_mode_cbc.py", line 274, in _create_cbc_cipher
cipher_state = factory._create_base_cipher(kwargs)
File "C:\Users\artur\AppData\Local\Programs\Python\Python39\lib\site-packages\Crypto\Cipher\AES.py", line 103, in _create_base_cipher
result = start_operation(c_uint8_ptr(key),
File "C:\Users\artur\AppData\Local\Programs\Python\Python39\lib\site-packages\Crypto\Util\_raw_api.py", line 243, in c_uint8_ptr
raise TypeError("Object type %s cannot be passed to C code" % type(data))
TypeError: Object type <class 'str'> cannot be passed to C code
然后更改第 34 行
decryptor = AES.new(HEADER_KEY, AES.MODE_CBC, 16 * '\x00')
至
decryptor = AES.new(HEADER_KEY.decode("utf8"), AES.MODE_CBC, 16 * '\x00')
收到此错误消息
File "C:\unssz.py", line 58, in <module>
main()
File "C:\unssz.py", line 34, in main
decryptor = AES.new(HEADER_KEY.encode("utf8"), AES.MODE_CBC, 16 * '\x00')
File "C:\Users\artur\AppData\Local\Programs\Python\Python39\lib\site-packages\Crypto\Cipher\AES.py", line 232, in new
return _create_cipher(sys.modules[__name__], key, mode, *args, **kwargs)
File "C:\Users\artur\AppData\Local\Programs\Python\Python39\lib\site-packages\Crypto\Cipher\__init__.py", line 79, in _create_cipher
return modes[mode](factory, **kwargs)
File "C:\Users\artur\AppData\Local\Programs\Python\Python39\lib\site-packages\Crypto\Cipher\_mode_cbc.py", line 274, in _create_cbc_cipher
cipher_state = factory._create_base_cipher(kwargs)
File "C:\Users\artur\AppData\Local\Programs\Python\Python39\lib\site-packages\Crypto\Cipher\AES.py", line 93, in _create_base_cipher
raise ValueError("Incorrect AES key length (%d bytes)" % len(key))
ValueError: Incorrect AES key length (19 bytes)
这里有什么问题,如何使它工作?我正在尝试解密三星安全区加密容器 .msr 文件(忘记密码)
from __future__ import print_function
from Crypto.Cipher import AES
import sys
CHUNK_SIZE = 4096
HEADER_SIZE = 16384
# AES key, for different crypto algorithms, different keys.
HEADER_KEY = '\x06\x42\x21\x98\x03\x69\x5E\xB1\x5F\x40\x60\x8C\x2E\x36\x00\x06'
def main():
with open(sys.argv[1], 'rb') as input_file:
header_enc = input_file.read(HEADER_SIZE)
decryptor = AES.new(HEADER_KEY, AES.MODE_CBC, 16 * '\x00')
header_dec = decryptor.decrypt(header_enc)
body_decryption_key = header_dec[0x203c:0x204C]
print('Decoding key: {}'.format(body_decryption_key.encode('hex')))
if len(sys.argv) != 3:
print('No output file specified, giving up...')
sys.exit(0)
decryptor = AES.new(body_decryption_key, AES.MODE_ECB, 16 * '\00')
with open(sys.argv[2], 'wb') as output_file:
while True:
chunk_enc = input_file.read(CHUNK_SIZE)
if len(chunk_enc) == 0:
break
chunk_dec = decryptor.decrypt(chunk_enc)
output_file.write(chunk_dec)
sys.stdout.write('.')
sys.stdout.flush()
if __name__ == "__main__":
main()
解决方案
推荐阅读
- mysql - 试图用 MySQL 和进程来理解 Django select_for_update()
- c - 运行脚本,获取其输出并从 c 程序打印
- java - 编译的程序没有输出
- scala - Scala,PureConfig - 如何读取 json 配置文件?
- python - 数据框中的正则表达式(熊猫)
- python - 使用 scapy 将数据包大小增加 2 个字节
- julia - 难道没有更好的方法来组合多个`Union{T,Nothing}`
- python - 如何保留在 python GUI 中所做的更改?
- python - 我发现错误“模块对象不可调用”
- amazon-web-services - 尝试在 aws emr 上另存为表时触发作业超时