In my addon I want to implement two features.
First will be simple lock (with password) to prevent other users of the PC edit anything in the addon.
Second should allow user to encrypt his data using the same password (I will be implementing this later, but I want to be ready for it).
Use case is simple - user creates some master password that will be required to unlock UI.
Regarding implementation, my first thought was simply hash user password and store the hash in the storage. For example using the SubtleCrypto.digest().
However the more I read about security, the less confident I feel. This solution would allow malicious users of the PC access the hash and use brute-force or dictionary attack to get the original password, which is unacceptable.
So my second thought was to use SubtleCrypto.importKey() and then SubtleCrypto.deriveKey() , just like in the example code here.
In the example code, the following part creates CryptoKey
:
await window.crypto.subtle.deriveKey(
{
"name": "PBKDF2",
salt: salt,
"iterations": 100000,
"hash": "SHA-256"
},
keyMaterial,
{ "name": "AES-GCM", "length": 256},
true,
[ "encrypt", "decrypt" ]
);
Now this looks much better because I see some salt and huge number of iterations, plus I can use this key to encrypt data and I can even store this CryptoKey
object in storage.
Now the question is:
- is this approach safe enough?
- how do I verify user password against the stored
CryptoKey
???