When generating a public-private key pair you have the option to secure the keystore with a password.

where is that password stored, is it a hashed version that is stored and if that is so which hashing algorithm is used ?

  • 3
    $\begingroup$ "When generating a public-private key pair", which/what software? If the software is written correctly, the password is not stored anywhere. Instead it is turned into a key and used to encrypt the private key. Then you can only access it by supplying the same password and correctly decrypting. But we need to know what software you are talking about. $\endgroup$ – mikeazo Jan 10 '17 at 21:17
  • $\begingroup$ However, if it was my key store implementation then I'd also store a derived hash and use that to check if the user input was correct (so that you don't have to decrypt the entire key store to detect the correctness of the password). So agree with mikeazo, we need to know the software or protocol + configuration to explain what is happening. Some key stores use multiple passwords, some are encrypted with a device specific key, are unlocked using biometric data such as fingerprints, heck the could be stored over several devices. Anything is possible really. $\endgroup$ – Maarten Bodewes Jan 10 '17 at 22:01
  • $\begingroup$ specifically from within Android studio when wanting to sign an apk, and from within puttygen of putty as to generate keys for use with SSH $\endgroup$ – microwth Jan 11 '17 at 5:37
  • $\begingroup$ @mikeazo "is not stored anywhere " if nothing is stored, not even a hash, what do you compare the password entered with as to decrypt the file? $\endgroup$ – microwth Jan 11 '17 at 5:41

There are a lot of fancy things one can do when we start talking about sharing access a key store that Maarten mentions in this comment. I'll stick with just a very simple setup. You have a private key file (e.g., ssh private key). You don't want that file accessible to an attacker who steals your laptop, so the software asks you to supply a password to control access to that file.

The way these typically work is that symmetric keys are generated using your password (e.g., using bcrypt or PFKDF2). The keys are then used to encrypt the private key file. This would be done using an authenticated encryption mode of operation. These modes produce the ciphertext and a tag, which can be used to ensure that the ciphertext has not changed (note: a MAC like HMAC over the ciphertext would also work).

Now, when you supply a password again in the future to decrypt the file, the software runs that password through the same function to generate a key. If the same password is supplied, the same key is generated. Then it can attempt to decrypt the file. If the wrong key is supplied, or the ciphertext has been altered, decryption will fail due to the mode of operation used.

So it is the authentication tag over the ciphertext that is used to determine if either the wrong password was supplied or the ciphertext was altered.

| improve this answer | |
  • $\begingroup$ " If the same password is supplied, the same key is generated. Then it can attempt to decrypt the file." that is what I'm after. This key is compared against what value to find out if it is the correct one? $\endgroup$ – microwth Jan 11 '17 at 12:06
  • $\begingroup$ @microwth: If the wrong key is generated, the MAC verification will fail. $\endgroup$ – Henrick Hellström Jan 11 '17 at 12:11
  • $\begingroup$ so there is something stored like th hash of the key so that it can be checked for validity, right? $\endgroup$ – microwth Jan 11 '17 at 12:14
  • 2
    $\begingroup$ @microwth like the hash of the key, no. What is stored is the ciphertext and an authentication tag. When decrypting, the software passes to the decryption function the ciphertext, the authentication tag, and the password. There are two possible outcomes, either all of those are correct and you get the plaintext back, or one of those is incorrect and you get an error. You have no idea which of the three is incorrect, however. $\endgroup$ – mikeazo Jan 11 '17 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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