From 3148cfd3741e0e9e50916c667748e7750a34d29b Mon Sep 17 00:00:00 2001 From: Pavel 'LEdoian' Turinsky Date: Sun, 9 Jan 2022 19:01:30 +0100 Subject: [PATCH] Add padding PyCryptodome does not seem to support ciphertext stealing --- munge.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/munge.py b/munge.py index 110cc26..29a0580 100644 --- a/munge.py +++ b/munge.py @@ -1,4 +1,5 @@ from Crypto.Cipher import AES +from Crypto.Util.Padding import pad, unpad from authorizedkeys.parser import parse_file, dump_file, AuthorizedKey import sys from base64 import b64decode, b64encode @@ -23,7 +24,7 @@ keys = parse_file(input) for k in keys: if isinstance(k, AuthorizedKey): if encrypt: - k.comment = b64encode(cipher.encrypt(k.comment.encode())).decode() + k.comment = b64encode(cipher.encrypt(pad(k.comment.encode(), cipher.block_size))).decode() else: # And now this is just wow. - k.comment = cipher.decrypt(b64decode(k.comment)).decode() + k.comment = unpad(cipher.decrypt(b64decode(k.comment)), cipher.block_size).decode() dump_file(keys, output)