π VaultBox – Lock/Unlock Any File in 1 Click with Python GUI | FuzzuTech
Demo :
Click Video πππ
Features:
-
Instant file encryption & decryption
-
Auto log tracking
-
Beginner-friendly CustomTkinter UI
-
Works offline
-
100% open source
Code :
import customtkinter as ctk
from tkinter import filedialog
import os, json
from cryptography.fernet import Fernet
from datetime import datetime
ctk.set_appearance_mode("dark")
ctk.set_default_color_theme("blue")
KEY_FILE = "vault.key"
LOG_FILE = "access_log.json"
# Generate key if not exists
if not os.path.exists(KEY_FILE):
with open(KEY_FILE, "wb") as f:
f.write(Fernet.generate_key())
with open(KEY_FILE, "rb") as f:
key = f.read()
fernet = Fernet(key)
if not os.path.exists(LOG_FILE):
with open(LOG_FILE, "w") as f:
json.dump([], f)
class VaultBox(ctk.CTk):
def __init__(self):
super().__init__()
self.title("π VaultBox - File Locker")
self.geometry("400x500")
self.resizable(False, False)
ctk.CTkLabel(self, text="VaultBox", font=("Arial", 24, "bold")).pack(pady=20)
self.status_label = ctk.CTkLabel(self, text="Select a file to lock or unlock.")
self.status_label.pack(pady=10)
ctk.CTkButton(self, text="π Lock File", command=self.lock_file).pack(pady=10)
ctk.CTkButton(self, text="π Unlock File", command=self.unlock_file).pack(pady=10)
ctk.CTkButton(self, text="π View Access Log", command=self.view_logs).pack(pady=20)
def log_action(self, file, action):
with open(LOG_FILE, "r") as f:
logs = json.load(f)
logs.append({
"file": os.path.basename(file),
"action": action,
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
})
with open(LOG_FILE, "w") as f:
json.dump(logs, f, indent=4)
def lock_file(self):
file = filedialog.askopenfilename()
if file:
with open(file, "rb") as f:
data = f.read()
encrypted = fernet.encrypt(data)
with open(file + ".locked", "wb") as f:
f.write(encrypted)
os.remove(file)
self.status_label.configure(text=f"π File Locked: {os.path.basename(file)}")
self.log_action(file, "Locked")
def unlock_file(self):
file = filedialog.askopenfilename(filetypes=[("Locked Files", "*.locked")])
if file:
with open(file, "rb") as f:
encrypted = f.read()
try:
decrypted = fernet.decrypt(encrypted)
orig_name = file.replace(".locked", "")
with open(orig_name, "wb") as f:
f.write(decrypted)
os.remove(file)
self.status_label.configure(text=f"π File Unlocked: {os.path.basename(orig_name)}")
self.log_action(file, "Unlocked")
except:
self.status_label.configure(text="❌ Invalid key or file error!")
def view_logs(self):
top = ctk.CTkToplevel(self)
top.title("π Access Log")
top.geometry("300x400")
with open(LOG_FILE, "r") as f:
logs = json.load(f)
for entry in reversed(logs[-10:]):
ctk.CTkLabel(top, text=f"{entry['timestamp']} - {entry['action']}: {entry['file']}").pack(pady=2)
if __name__ == "__main__":
app = VaultBox()
app.mainloop()
Comments
Post a Comment