After creating a simple python encryption code with fernet library (that worked great) I tried to code a decryptor but unfortunately while trying to use my decryptor i got the following error
['blahblahblah.txt', 'blah.txt']
Traceback (most recent call last):
File "/home/kali/Desktop/stuff/projects/voldemort/decrypt.py", line 24, in <module>
contents_decrypted = Fernet(secretkey).decrypt(contents)
File "/usr/lib/python3/dist-packages/cryptography/fernet.py", line 34, in __init__
raise ValueError(
ValueError: Fernet key must be 32 url-safe base64-encoded bytes.
The Code:
#!/usr/bin/python3
import os
from cryptography.fernet import Fernet
#find some files
files = []
#Starting the file in a loop
for file in os.listdir():
if file == "voldemort.py" or file == "thekey.key" or file == "decrypt.py":
continue
if os.path.isfile(file):
files.append(file)
print(files)
with open("thekey.key", "rb") as key:
secretkey = key.read()
for file in files:
with open(file, "rb") as thefile:
contents = thefile.read()
contents_decrypted = Fernet(secretkey).decrypt(contents)
with open(file, "wb") as thefile:
thefile.write(contents_decrypted)