I'm trying to make a basic encryption/decryption script for personal use, and it works perfectly fine. I'm posting this in the infosec section because my question revolves around how easy it is to break the encryption.
NOTE: I know little about cryptology, hence the simplistic question.
Here is a quick mock-up of my code:
from Crypto.Cipher import AES import hashlib from random import randint import struct from getpass import getpass import os infile = sys.argv password = hashlib.sha256(getpass('[*] Enter Password: ')).digest() ivector = ''.join(chr(randint(0, 0xFF)) for i in range(16)) encryptor = AES.new(password, AES.MODE_CBC, ivector) with open(infile, 'rb') as infile: to_encrypt = infile.read() to_encrypt += 'password_is_correct' while len(to_encrypt)%16 != 0: to_encrypt += ' ' #Pad file to a multiple of 16 for encryption encrypted = encryptor.encrypt(to_encrypt) size = os.path.getsize(infile) with open(infile, 'wb') as outfile: outfile.write(struct.pack(size, '<Q')) outfile.write(ivector) outfile.write(encrypted) print '[*] Encryption Completed!'
To summarize. This code will encrypt a file with a random initialization vector and a password given by the user. It will read the file to encrypt and will append the string "password_is_correct" to the end of the string. Upon decryption, the initialization vector will be read from the file, and a password will be taken from the user. If the password is correct, then the string "password_is_correct" should be in the decrypted string. Is this a valid method a password verification? Does this pose any sort of risk to file integrity as to easing the file cracking process?
The full code can be found here.