I am using M2Crypto in python with the following code:
import M2Crypto;
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:
while True:
buf = infile.read(1024)
if not buf:
break
print buf+"."
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()
encrypt_file("1234", "D:\\in.txt", "D:\\out.txt", "00")
decrypt_file("1234", "D:\\out.txt", "D:\\dec.txt", "00")
The problem is that I don't get in.txt
content in the dec.txt
file. Am I not using this right?