How can I hash a password in Java?

前端 未结 13 2013
暖寄归人
暖寄归人 2020-11-22 05:00

I need to hash passwords for storage in a database. How can I do this in Java?

I was hoping to take the plain text password, add a random salt, then store the salt a

13条回答
  •  逝去的感伤
    2020-11-22 05:40

    In addition to bcrypt and PBKDF2 mentioned in other answers, I would recommend looking at scrypt

    MD5 and SHA-1 are not recommended as they are relatively fast thus using "rent per hour" distributed computing (e.g. EC2) or a modern high end GPU one can "crack" passwords using brute force / dictionary attacks in relatively low costs and reasonable time.

    If you must use them, then at least iterate the algorithm a predefined significant amount of times (1000+).

    • See here for more: https://security.stackexchange.com/questions/211/how-to-securely-hash-passwords

    • And here: http://codahale.com/how-to-safely-store-a-password/ (criticizes SHA family, MD5 etc for password hashing purposes)

    • And here: http://www.unlimitednovelty.com/2012/03/dont-use-bcrypt.html (criticizes bcrypt and recommends scrypt and PBKDF2)

提交回复
热议问题