This script securely encrypts or decrypts passwords on disk within a custom database file. It also features functionality to retrieve passwords from a previously generated database file. This script takes a master password from stdin/from memory, then hashes the password using the specified hashing algorithm passed to the algorithm parameter/-a (scrypt, sha256) and finally AES-256 encrypts/decrypts the file’s data using the algorithm’s hash as the AES-256 key. When providing the ‘scrypt’ argument to the algorithm parameter the script will generate a custom scrypt salt per each database file edit or creation. The uniquely ge nerated salt is base64 encoded and prepended to each database file’s encrypted bytes separated by carriage return line feed bytes (for parsing) as meta-data. When using the change password parameter/-cp the script will decrypt the database file’s data into memory, write random bytes*WIPE_PASSES to the database file, truncate the file and finally write the new data AES-256 encrypted with the new hashed master password to the database file. Effectively making data recovery/forensics difficult.
Example usage using scrypt as the hashing algorithm:
Create a database file:
<div class="snippet-clipboard-content position-relative" data-snippet-clipboard-copy-content="python3 aespasswd_store.py -a scrypt -c “>
python3 aespasswd_store.py -a scrypt -c <filename>