I'm trying to make a password manager for Windows installed computers, and after researching the best ways to encrypt the passwords in the database (I'm new to cryptography) I think I've come up with a good way to do it, but I'm still not sure.
How the key is made when the user first opens the program:
- The user inputs the master password, the password that will unlock the password database.
- A random salt of 16 bytes and the master password will be put through a KDF (PBKDF2 using SHA512) to derive a key $k$. $$k = \operatorname{PBKDF2-SHA-512}(password, salt)$$
How the database is encrypted:
Using the $k$, the database is encrypted using AES 256 bit CBC. $$ c = \operatorname{AES-CBC}(k,IV, database)$$
The $IV$ and the encrypted database $c$ are then encoded to base64 before store.
Where and how the database, salt (for the key $k$) and the $IV$ (for AES) are stored:
The salt, $IV$ and encrypted database will be dumped into a python dictionary, and written to a txt file e.g.
{"salt": "T\x96\x829\xed\...", "iv": "00/JOAIsHs9XtB5acawBhA==", "database": "TE4nhDRTJ+JW..."}
The decrypted database file is then deleted and overwritten with random encrypted data multiple times to properly wipe it.
This txt file is then encrypted with AES 256 bit CBC, the key is 32 random bytes which is then hidden somewhere on the computer (could this part be skipped?).
I would prefer if no external devices would have to be used to store the second encryption key.
Also, every time the database is decrypted, and then encrypted back again when the user is done, a new key with a different salt is produced, and a new IV for encryption is produced.
Is this how it's supposed to be done? Or am I completely wrong?