print("You have not installed the required modules. Follow these steps to do so:\n\n1. Open the terminal (Linux/MacOS) or command prompt (Windows).\n2. Navigate to this directory and then to the files directory.\n3. Type 'pip install -r dependencies.txt'.\n4. Restart the program.\n\nIf you have followed all the steps correctly, keyvault will work on the next start.")
exit()
defencrypt_db(password):
binpass=password.encode()
salt=urandom(16)
kdf=PBKDF2HMAC(
algorithm=hashes.SHA512(),
length=32,
salt=salt,
iterations=1500000,
)
key=base64.urlsafe_b64encode(kdf.derive(binpass))
fernet=Fernet(key)
withopen("database/db.dat","rb")asf:
data=f.read()
encr=fernet.encrypt(data)
withopen("database/db.asc","wb")asf:
f.write(encr)
withopen("database/db.s","wb")asf:
f.write(salt)
defdecrypt_db(password):
withopen("database/db.s","rb")asf:
salt=f.read()
binpass=password.encode()
kdf=PBKDF2HMAC(
algorithm=hashes.SHA512(),
length=32,
salt=salt,
iterations=1500000,
)
key=base64.urlsafe_b64encode(kdf.derive(binpass))
fernet=Fernet(key)
withopen("database/db.asc","rb")asf:
encrypted_data=f.read()
decr=fernet.decrypt(encrypted_data)
withopen("database/db.dat","wb")asf:
f.write(decr)
withopen("database/db.dat","rb")asf:
defdatabase_enc():
whileTrue:
conn=sc.connect("database/keyvault.db")
cursor=conn.cursor()
ifpath.isfile("database/keyvault.db"):
for_inrange(3):
try:
try:
db=pickle.load(f)
password=gp(prompt="Enter master password: ")
exceptEOFError:
conn.execute(f"PRAGMA key = {password}")
print("\nDatabase loaded.")
conn.execute('''
CREATETABLEIFNOTEXISTSdata(
idINTEGERPRIMARYKEYAUTOINCREMENT,
serviceTEXT,
usernameTEXT,
emailTEXT,
passwordTEXT,
websiteTEXT,
categoryTEXT,
notesTEXT,
totpTEXT)
''')
passCorrect=True
break
break
shred()
exceptsc.DatabaseError:
print("Incorrect password.\n")
passCorrect=False
defshred():
ifnotpassCorrect:
withopen("database/db.dat","wb")asf:
print("You have entered a wrong password three times. Please restart the program to try again.")