-
Notifications
You must be signed in to change notification settings - Fork 0
/
decrypt.py
60 lines (39 loc) · 1.44 KB
/
decrypt.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
import os
from wcmatch import glob
from cryptography.fernet import Fernet
def decryptfile(_filename, _encData, _key):
try:
decMessage = fernet.decrypt(_encData)
fencode = open(_filename,"wb")
fencode.write(decMessage)
fencode.close()
print(_filename+" >> decrypt success")
os.rename(_filename, _filename.replace('.stpdev', ''))
except Exception as e:
print(e)
if __name__ == "__main__":
# input private key decrypt data
private_key = bytes(input("Enter key: "), 'utf-8')
fernet = Fernet(private_key)
_rootpath = "D:/encrypt_python3/.list_encrypted.txt"
f = open(_rootpath, "r", encoding="utf-8")
readdata = f.read()
datatoarray = readdata.split("|")
datatoarray.remove('')
f.close()
for fileencodes in datatoarray:
filename = fileencodes
try:
f = open(filename, "r")
readdata = f.read()
f.close()
# we will be encryting the below string.
encData = bytes(readdata, 'utf-8')
# decrypt the encrypted string with the
# Fernet instance of the key,
# that was used for encrypting the string
# encoded byte string is returned by decrypt method,
# so decode it to string with decode methods
decryptfile(fileencodes, encData, private_key)
except Exception as e:
print(e)