Typically, you should encrypt the data key with a password.
For encryption, the password will first be converted to a key. To do this, you would use the password-based key detection function (PBKDF). PBKDF2 is currently the most standard option.
You encrypt data using a randomly generated key. This key, in turn, is encrypted using the key generated by the password.
To change the password, first ask for the original. Then decrypt the data key. You can then request a new password and re-encrypt the data key. Encrypted data should not be affected.
source share