作为对此的一点背景介绍,我正在将一个java文件转换为python,并且正在执行最后一个操作。我在大约200LOC,所以它使它更边缘的座位…
无论如何,在java中,操作是:
Cipher cipher = Cipher.getInstance("AES/ecb/nopadding");
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(keys[i], "AES"));
//doFinal(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset)
cipher.doFinal(save, saveOffset, 16, save, saveOffset);
在python中,我有这样的代码:
from Crypto.Cipher import AES
cipher = AES.new(bytes(keys[i]), AES.MODE_ECB)
cipher.decrypt(?????)
这段代码取自decrypt()下的包:
:Parameters:
ciphertext : bytes/bytearray/memoryview
The piece of data to decrypt.
The length must be multiple of the cipher block length.
:Keywords:
output : bytearray/memoryview
The location where the plaintext must be written to.
If ``None``, the plaintext is returned.
:Return:
If ``output`` is ``None``, the plaintext is returned as ``bytes``.
Otherwise, ``None``.
正如您所看到的,.decrypt()实际上并没有偏移量的输入,但是我想知道是否有什么方法可以解决这个问题?
这就是为什么我决定发布,所以,我可以发送:
temp_bytes = save[offset]
temp_decrypt = cipher.decrypt(temp_bytes)
save[offset] = temp_decrypt
或者在解密时,它是否使用整个文件作为上下文,而我将得到错误的输出?我很乐意这样做,并测试它,但输出只是胡言乱语,我将不得不编写另一个程序来解析(另一个java到python项目)。
发布于 2020-04-25 00:49:29
最终起作用的是:
save[saveOffset:saveOffset+16] = cipher.decrypt(save[saveOffset:saveOffset+16])
没想到它能这么容易地工作
https://stackoverflow.com/questions/61419099
复制相似问题