Advertisement
AceScottie

encryption

Aug 1st, 2018
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. import hashlib
  2. from Crypto.Cipher import AES
  3. def encrypt_file(key, dir, file, out_filename, chunksize=64*1024):
  4.         iv = str(binascii.b2a_hex(os.urandom(15)))[:16]
  5.         encryptor = AES.new(key, AES.MODE_CBC, iv)
  6.         in_filename = dir+file
  7.         filesize = os.path.getsize(in_filename)
  8.         with open(in_filename, 'rb') as infile:
  9.             with open(out_filename, 'wb') as outfile:
  10.                 outfile.write(struct.pack('<Q', filesize))
  11.                 outfile.write(iv)
  12.                 while True:
  13.                     chunk = infile.read(chunksize)
  14.                     if len(chunk) == 0:
  15.                         break
  16.                     elif len(chunk) % 16 != 0:
  17.                         chunk += ' ' * (16 - len(chunk) % 16)
  18.                     outfile.write(encryptor.encrypt(chunk))
  19.  
  20. def genMD5pass(passwd):
  21.     m = hashlib.md5()
  22.     m.update(passwd)
  23.     passwd = m.hexdigest()
  24.     return passwd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement