def encrypt_file(key, in_filename, out_filename,iv): cipher=M2Crypto.EVP.Cipher('aes_256_cfb',key,iv, op=1) with open(in_filename, 'rb') as infile: with open(out_filename, 'wb') as outfile: outfile.write(b) while True: buf = infile.read(1024) if not buf: break outfile.write(cipher.update(buf)) outfile.write( cipher.final() ) outfile.close() infile.close() def decrypt_file(key, in_filename, out_filename,iv): cipher = M2Crypto.EVP.Cipher("aes_256_cfb",key , iv, op = 0) with open(in_filename, 'rb') as infile: with open(out_filename, 'wb') as outfile: while True: buf = infile.read(1024) if not buf: break try: outfile.write(cipher.update(buf)) except: print "here" outfile.write( cipher.final() ) outfile.close() infile.close()
imp
source share