-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
111 lines (73 loc) · 1.87 KB
/
main.py
File metadata and controls
111 lines (73 loc) · 1.87 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import eel
from gpg import GPGEncrypt
import tkinter
import tkinter.filedialog
# interface
gpg = GPGEncrypt()
# List public keys
@eel.expose
def listPublicKeys():
return gpg.listPublicKeys()
# List private keys
@eel.expose
def listPrivateKeys():
return gpg.listPrivateKeys()
# Delete public keys
@eel.expose
def deleteKey(fingerprint, password):
return gpg.deleteKey(fingerprint, password)
# Generate key
@eel.expose
def generateKey(name, password):
return gpg.generateKey(name, password)
# Encrypt File
@eel.expose
def encryptFile(path, recipient, save_path):
encryptedData = ''
with open(path, 'rb') as f:
encryptedData = str(gpg.encryptFile(f, recipient))
with open(save_path, 'w') as f:
f.write(encryptedData)
return 'Successfully encrypted file'
# Decrypt data from file.
@eel.expose
def decryptFile(path, save_file):
decryptedData = ''
with open(path, 'rb') as f:
decryptedData = str(gpg.decryptFile(f))
print(decryptedData)
with open(save_file, 'w') as f:
f.write(decryptedData)
return "Successfully decrypted file"
# Export Keys
@eel.expose
def exportKeys(keyid):
keys = gpg.exportKeys(keyid)
path = saveFileDialog()
with open(path, 'w') as f:
f.write(keys)
return "Successfully export keys"
# Import keys
@eel.expose
def importKey():
path = getFileDialog()
with open(path, 'r') as f:
gpg.importKeys(f.read())
return "Successfully import keys"
# get file path
@eel.expose
def getFileDialog():
top = tkinter.Tk()
path = tkinter.filedialog.askopenfilename()
top.destroy()
return path
# Save file dialog
@eel.expose
def saveFileDialog():
top = tkinter.Tk()
path = tkinter.filedialog.asksaveasfilename()
top.destroy()
return path
# eel initial
eel.init('web')
eel.start('main.html', port=0, size=(900, 500))