I am using the simplecrypt
library to encrypt a file, however I cannot seem to read the file in a way that simplecrypt
can decode it.
Encryption code:
from simplecrypt import encrypt, decrypt
def encrypt_file(file_name, key):
with open(file_name, 'rb') as fo:
plaintext = fo.read()
enc = encrypt(plaintext, key)
with open(file_name + ".enc", 'wb') as fo:
fo.write(enc)
encrypt_file("test.txt", "securepass")
This works fine and runs without any errors, however as soon as i try to decode it i get this error (using the below code)
simplecrypt.DecryptionException: Data to decrypt must be bytes; you cannot use a string because no string encoding will accept all possible characters.
from simplecrypt import encrypt, decrypt
def decrypt_file(file_name, key):
with open(file_name, 'rb') as fo:
ciphertext = fo.read()
dec = decrypt(ciphertext, key)
with open(file_name[:-4], 'wb') as fo:
fo.write(dec)
decrypt_file("test.txt.enc", "securepass")