-
Notifications
You must be signed in to change notification settings - Fork 0
/
encryption.py
66 lines (52 loc) · 1.44 KB
/
encryption.py
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
from cryptography.fernet import Fernet
import eel
import io
@eel.expose
def keyGen():
key = Fernet.generate_key()
file = open("Keys/key.key", "wb")
file.write(key)
file.close()
print("\nKey Created.\n")
def keyRead():
try:
file = open("Keys/key.key", "rb")
key = file.read()
file.close()
return key
except FileNotFoundError:
print("No Key exists, a new one has just been created.")
keyGen()
keyRead()
@eel.expose
def encrypt(fileName):
Key = keyRead()
with open("Files/" + fileName, "rb") as f:
data = f.read()
fernet = Fernet(Key)
encrypted = fernet.encrypt(data)
with open("encrypt/" + fileName, "wb") as f:
f.write(encrypted)
@eel.expose
def decrypt(fileName):
Key = keyRead()
with open("encrypt/" + fileName, "rb") as f:
data = f.read()
fernet = Fernet(Key)
decrypted = fernet.decrypt(data)
with open("Downloads/" + fileName, "wb") as f:
f.write(decrypted)
encrypt("u1.txt")
print("encrypted succesful")
import cloudinary
from cloudinary.uploader import upload
from pathlib import Path
cloudinary.config(
cloud_name="darx4fbqo",
api_key="349765384248479",
api_secret="vGw7sREkXTDzcApraF0iHfOYc3Q",
)
file_path = Path("C:/Users/Manoj Reddy/Desktop/btp/encrypt/u1.txt")
public_id = file_path.stem
response = upload(str(file_path), public_id=public_id, resource_type="raw")
print(response)