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.

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

1 Answer 1


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 and acknowledge you have read our privacy policy.

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