-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete-password.py
102 lines (95 loc) · 2.96 KB
/
delete-password.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
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
from cryptography.fernet import Fernet
import os
import random
import argparse,sys
import json
fpath = __file__
absolute_path = os.path.abspath(fpath)
base_dir = os.path.dirname(absolute_path)
epicPath = base_dir + '/passwords/'
keyPath = base_dir + '/special/'
passlockname = keyPath + 'lock.pws'
def decrypt(filename, key):
f = Fernet(key)
if not os.path.exists(passlockname):
print("Use save-password.py to generate your decryption key :(")
sys.exit()
with open(passlockname, "rb") as file:
encrypted_data = file.read()
file.close()
decrypted_data = f.decrypt(encrypted_data)
decdir = base_dir + '/decpass/'
if not os.path.exists(decdir):
os.mkdir(decdir)
decfile = decdir + 'dec-' + str(random.randrange(0,500000)) + '.pwsaver'
with open(decfile, "wb") as file:
file.write(decrypted_data)
file.close()
with open(decfile, "r") as file:
e = file.read()
file.close()
os.remove(decfile)
os.rmdir(decdir)
lol = input("Input your decryption key: ")
if lol == e:
print("Correct, deleting!")
else:
input("Incorrect.")
sys.exit()
with open(filename, "rb") as file:
encrypted_data = file.read()
file.close()
os.remove(filename)
decrypted_data = f.decrypt(encrypted_data)
decdir = base_dir + '/decpass/'
if not os.path.exists(decdir):
os.mkdir(decdir)
decfile = decdir + 'dec-' + str(random.randrange(0,500000)) + '.pwsaver'
with open(decfile, "wb") as file:
file.write(decrypted_data)
file.close()
with open(decfile, "r") as file:
e = file.read()
pp = json.loads(e)
print("="*40, "Decrypted Password", "="*40)
print("Name - ",pp['name'])
print("User/Email - ",pp['email'])
print("Password - ",pp['passphrase'])
print("=" * 40, "Decrypted Password", "=" * 40)
print("Password deleted.")
file.close()
os.remove(decfile)
os.rmdir(decdir)
def load_key():
fpath = __file__
absolute_path = os.path.abspath(fpath)
base_dir = os.path.dirname(absolute_path)
epicPath = base_dir + '/special/'
file_name = epicPath + 'spec.key'
return open(file_name, "rb").read()
def start():
id = input("Enter name of password: ")
full_path = epicPath + id + '.pwsaver'
key = load_key()
if os.path.exists(full_path):
decrypt(full_path, key)
else:
print("File does not exist!")
start()
parser = argparse.ArgumentParser()
parser.add_argument("-N", "--name", help="get a password")
parser.add_argument("-D", "--delete", help="get", action="store_true")
args = parser.parse_args()
if args.delete:
if args.name:
full_path = epicPath + args.name + '.pwsaver'
key = load_key()
if os.path.exists(full_path):
decrypt(full_path, key)
else:
print("File does not exist!")
sys.exit()
else:
start()
else:
start()