I'm trying to cipher files using symmetric key. Since I'm not able to o this, I'm doing some tests using the file (.txt) content and ciphering that same content using symmetric key and everything works fine:
filename1 = raw_input("Insert file name: ")
with open(filename1,'rb') as f:
s = f.read()
data1 = s
# insert password to create key
password1 = raw_input('Enter password (symmetric key): ')
# generate 16bytes (AES-128) key from inserted password
h1 = SHA256.new()
h1.update(password1)
key1 = h1.digest()[0:16]
# generate initialization 16bytes vector
iv1 = Random.new().read(16)
# criptogram creation (cipher data)
cipher1 = AES.new(key1, AES.MODE_CFB, iv1)
criptogram1 = iv1 + cipher1.encrypt(data1)
But, what I need is to use the symmetric key ciphering to cipher files, not just the content like I'm doing at the moment. I need to be able to choose the file and then use the symmetric key in it.
Edit: For "cipher files, not just the content"? I mean that I can encrypt something inside a .txt file, something written in it, but I want to be able to encrypt 'directly' the file, I don't want to open it and read what is inside and then encrypt that... The example that I post, I'm entering a file name (e.g. xpto.txt) wich has something written inside (e.g. Hello world!), so in the example I'm just encrypting that content.
I want to get a file encrypted with out have to read what is inside of it. Because if I try to encrypt a picture, I'm not going to read inside it like in a .txt file, I want to get the entire file and encrypt it.