Segue o código...
import os, random
from Crypto.Cipher import AES
import glob
def encrypt(filename):
chunksize = 64 * 1024
output_file = "(encrypted)" + filename
filesize = str(os.path.getsize(filename)).zfill(16)
#key = "{: <32}".format(filename).encode("utf-8")
IV = ""
for i in range(16):
IV += chr(random.randint(0, 0xFF))
encryptor = AES.new(AES.MODE_CBC, IV)
with open(filename, "rb") as infile:
with open(output_file, "wb") as outfile:
outfile.write(filesize)
outfile.write(IV)
while True:
chunk = infile.read(chunksize)
if len(chunk) == 0:
break
elif len(chunk) % 16 != 0:
chunk += " " * (16 - (len(chunk) % 16))
outfile.write(encryptor.encrypt(chunk))
os.chdir('/home/usuario/Documentos/Teste')
for f in glob.glob('*'):
encrypt(f)
O error que aparece:
TypeError: argument 1 must be string or read-only buffer, not int
↧