Foro de elhacker.net

Programación => Scripting => Mensaje iniciado por: Th3_K1d en 10 Noviembre 2017, 01:47 am



Título: Necesito ayuda con PyCrypto
Publicado por: Th3_K1d en 10 Noviembre 2017, 01:47 am
Hola, hace unos días me topé con este código en python que cifra archivos con claves AES usando el módulo PyCrypto, el problema es que no encuentro forma de hacer un código que decifre el archivo, si alguien me pudiese ayudar lo agradecería.

Uso python 2.7.13.

Código:
# -*- coding: utf8 -*-
import os, fnmatch, struct, random, string, base64, platform, sys, time, socket, json, urllib, ctypes, urllib
from Crypto import Random
from Crypto.Cipher import AES

KEY = ''.join([ random.choice(string.ascii_letters + string.digits) for n in xrange(32) ])

def encrypt(key, in_filename, newfilename, out_filename = None, chunksize = 65536, Block = 16):
    if not out_filename:
        out_filename = newfilename
    iv = Random.new().read(AES.block_size)
    encryptor = AES.new(key, AES.MODE_CBC, iv)
    filesize = os.path.getsize(in_filename)
    with open(in_filename, 'rb') as infile:
        with open(out_filename, 'wb') as outfile:
            outfile.write(struct.pack('<Q', 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))