So I wish to encrypt a string using AES-256 and want to provide the user to specify the password for unlocking the string. I plan to use sha-256 to hash to users entered password and use this as the key. Is this secure? and is their a better way of doing this?

Edit: it would be nice if people left a comment about why they down-voted it.

  • 3
    $\begingroup$ No it is not secure. Yes there are better ways. Look at Argon and SCrypt. $\endgroup$ – Thomas M. DuBuisson Apr 1 '18 at 23:46
  • $\begingroup$ @ThomasM.DuBuisson Thank you I didn't know about this I'm new to cryptography thanks $\endgroup$ – Joss Bird Apr 1 '18 at 23:50
  • $\begingroup$ @ThomasM.DuBuisson would you please mind and convert your comment to a (short) answer with relevant links perhaps? $\endgroup$ – SEJPM Apr 2 '18 at 10:32
  • $\begingroup$ related crypto.stackexchange.com/questions/22678/… $\endgroup$ – Richie Frame Apr 2 '18 at 18:57
  • $\begingroup$ @RichieFrame quite different ngl $\endgroup$ – Joss Bird Apr 2 '18 at 23:22

Using a key derived from a password hash means someone could brute force this using either a known list of passwords or dictionary.

Since SHA-256 is quite fast, it's very easy to do with a moderate amount of computational power.

To better protect the key from such an attack, it is suggested to use a password derived from a key derivation function.

Some examples of these include: PBKDF2, scrypt and argon2.


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.