-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencrypt.py
More file actions
31 lines (29 loc) · 912 Bytes
/
Copy pathencrypt.py
File metadata and controls
31 lines (29 loc) · 912 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
import gnupg
import os
def setup_gpg():
"""Initialize GPG with default settings"""
try:
gpg = gnupg.GPG()
return gpg
except Exception as e:
print(f"Warning: GPG setup failed: {e}")
return None
def encrypt_file(filename):
"""Encrypt the given file using GPG"""
try:
gpg = setup_gpg()
if gpg:
with open(filename, 'rb') as f:
status = gpg.encrypt_file(
f,
recipients=None,
symmetric='AES256',
passphrase='usbdetector',
output=f'{filename}.gpg'
)
if status.ok:
os.remove(filename) # Remove original file after encryption
return True
except Exception as e:
print(f"Warning: Encryption failed: {e}")
return False