Open
Description
When use Zero Padding encrypt and decrypt, some types of files (such as .7z file) which ends with bytes '00' will damaged file.
I have encountered and reproduced this problem, and I use PKCS7 instead of Zero Padding and it worked.
I modified:
def pad(self, s):
pad_len = AES.block_size - len(s) % AES.block_size
padding = bytes([pad_len] * pad_len)
return s + padding
def decrypt(self, ciphertext, key):
iv = ciphertext[:AES.block_size]
cipher = AES.new(key, AES.MODE_CBC, iv)
plaintext = cipher.decrypt(ciphertext[AES.block_size:])
pad_len = plaintext[-1]
return plaintext[:-pad_len]
If you update the code as I did, please be sure to indicate in README.MD
that you have modified the code, otherwise users may not be able to use the updated code to decrypt the content encrypted by the old code
Activity