Add padding

PyCryptodome does not seem to support ciphertext stealing
master
LEdoian 3 years ago
parent f3ec923656
commit 3148cfd374

@ -1,4 +1,5 @@
from Crypto.Cipher import AES from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad
from authorizedkeys.parser import parse_file, dump_file, AuthorizedKey from authorizedkeys.parser import parse_file, dump_file, AuthorizedKey
import sys import sys
from base64 import b64decode, b64encode from base64 import b64decode, b64encode
@ -23,7 +24,7 @@ keys = parse_file(input)
for k in keys: for k in keys:
if isinstance(k, AuthorizedKey): if isinstance(k, AuthorizedKey):
if encrypt: 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. 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) dump_file(keys, output)

Loading…
Cancel
Save