-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencrypt_on_idle.py
More file actions
35 lines (28 loc) · 869 Bytes
/
encrypt_on_idle.py
File metadata and controls
35 lines (28 loc) · 869 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
30
31
32
33
34
35
import time
import os
from cryptography.fernet import Fernet
from activity_monitor import start_activity_monitor, idle_seconds
from crypto_utils import derive_key
from folder_crypto import encrypt_folder
IDLE_LIMIT = 600 #10 minutes
TARGET_FOLDER = "FolderPath"
start_activity_monitor()
password = input("Set encryption password: ")
SALT_FILE = ".salt"
if os.path.exists(SALT_FILE):
with open(SALT_FILE, "rb") as f:
salt = f.read()
else:
salt = os.urandom(16)
with open(SALT_FILE, "wb") as f:
f.write(salt)
key = derive_key(password, salt)
fernet = Fernet(key)
print("\n[+] Monitoring user activity...")
while True:
if idle_seconds() > IDLE_LIMIT:
print("\n[+] Idle detected. Encrypting folder...")
encrypt_folder(TARGET_FOLDER, fernet)
print("\n[+] Encryption complete.")
break
time.sleep(5)