我正在尝试在 PyCrypto 中重新创建第二个命令(解密)
openssl enc -aes-128-ecb -nosalt -base64 -pass pass:abcde -md sha256 -in test.txt -out out.txt
openssl enc -d -aes-128-ecb -nosalt -base64 -pass pass:abcde -md sha256 -in out.txt
的内容test.txt
是flag{flagflag}
。加密的输出是0KSF5koIceXxszsgzpl4uA==
。
binascii.a2b_base64(b'0KSF5koIceXxszsgzpl4uA==')
openssl enc -aes-128-ecb -nosalt -pass pass:abcde -md sha256 -in test.txt -out out.txt
产生与(no )相同的字节数组-base64
,所以我知道 base64 解码应该是第一步。
p = "abcde".encode()
h = SHA256.new(p)
key = h.hexdigest()[:32].upper()
key
与以下输出匹配,所以我知道密钥生成代码是正确的:
$ openssl enc -aes-128-ecb -nosalt -pass pass:abcde -base64 -md sha256 -in test.txt -v -P
key=36BBE50ED96841D10443BCB670D6554F
bufsize=8192
但是,将所有这些放在一起会在msg
. 任何我弄错的地方都将不胜感激。
from Crypto.Hash import SHA256
from Crypto.Cipher import AES
import binascii
c = binascii.a2b_base64(b'0KSF5koIceXxszsgzpl4uA==')
p = "abcde".encode()
h = SHA256.new(p)
key = h.hexdigest()[:32].upper()
cipher = AES.new(key.encode(), AES.MODE_ECB)
msg = cipher.decrypt(m)
print(msg)