Skip to content

Commit

Permalink
ROB: Padding issue with AES encryption (#1469)
Browse files Browse the repository at this point in the history
Fixes #1221

Credit goes to Alper Ahmetoglu for the fix

Co-authored-by: Alper Ahmetoglu <[email protected]>
  • Loading branch information
MartinThoma and alper111 authored Dec 10, 2022
1 parent 9821468 commit f804f3a
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions PyPDF2/_encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class CryptIdentity(CryptBase):

try:
from Crypto.Cipher import AES, ARC4 # type: ignore[import]
from Crypto.Util.Padding import pad # type: ignore[import]

class CryptRC4(CryptBase):
def __init__(self, key: bytes) -> None:
Expand All @@ -84,6 +85,8 @@ def decrypt(self, data: bytes) -> bytes:
iv = data[:16]
data = data[16:]
aes = AES.new(self.key, AES.MODE_CBC, iv)
if len(data) % 16:
data = pad(data, 16)
d = aes.decrypt(data)
if len(d) == 0:
return d
Expand Down

0 comments on commit f804f3a

Please sign in to comment.