Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import hashlib
- from Crypto.Cipher import AES
- def encrypt_file(key, dir, file, out_filename, chunksize=64*1024):
- iv = str(binascii.b2a_hex(os.urandom(15)))[:16]
- encryptor = AES.new(key, AES.MODE_CBC, iv)
- in_filename = dir+file
- 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))
- def genMD5pass(passwd):
- m = hashlib.md5()
- m.update(passwd)
- passwd = m.hexdigest()
- return passwd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement