1
$\begingroup$

I am using Android's keystore to generate a key which is protected by fingerprint authentication. This key can be used to encrypt any secrets. In my case, I want to encrypt a user password (which is needed to access the app contents. Usually that's a reasonably strong letter-number-special-characters password.). The encrypted password is stored in the app's preferences. While these preferences are not fully public, I don't consider them secure storage.

Assuming an attacker has access to the encrypted password, I would like to expose as little as possible about the password itself. One thing that comes to my mind is password length. From the length of the encrypted text, it can be seen if the password is more than 16 characters or not. (I could hide this by always appending random text to have a fixed length of text for passwords < N characters, with N sufficiently high).

Are there any more serious issues? Is there any best practice on how to encrypt user passwords?

$\endgroup$
3
  • $\begingroup$ Do you need to actually use the password (like a password manager might)? If not, encryption is almost certainly the wrong idea and you should be using a password hash. $\endgroup$
    – otus
    Dec 30, 2015 at 9:33
  • $\begingroup$ Generally, encrypting passwords is not a good idea. Do you need to store the passwords to automatically authenticate the user to some external service (i.e. are you implementing something like a "password wallet"), or are you just using the passwords to grant the user access to your app? If the latter, you shouldn't be encrypting the passwords at all, but rather hashing them; if the former, can you switch to some other (e.g. public key based) authentication method? $\endgroup$ Dec 30, 2015 at 9:34
  • $\begingroup$ it's a password manager app. I need the password to decrypt a password database (Keepass format). Instead of storing the user password, I might as well think about storing the Database key (which is calculated by transforming the user password and optionally other data like from a key file or OTP provider). I would prefer to store the password from a perspective of user experience and simplicity of implementation, but that's not the only criterion, of course. $\endgroup$
    – Philipp
    Dec 30, 2015 at 9:38

1 Answer 1

1
$\begingroup$

Since you are talking about password-based encryption, the best practice is to use a slow password-based key derivation function to derive the encryption key and only store the salt (and parmeters used). You can verify the correctness of the password by using authenticated encryption, which you should most likely be doing in any case.

The password hash used could be scrypt, or I suppose argon2.

Since you are using this in a password manager -type situation, the encrypted data is passwords, which is fine. The above advice is only about the master password that is used to secure the database. That should not be stored in plaintext or encrypted form and even its hash does not need to be.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.