1

I read about BCryptPasswordEncoder here and I don't understand why this would be used rather than a hash+salt, there is no secret key involved all it takes to for an attacker to crack it is gaining access to the hash and using the algorithm's decode. I thought hash+salting required an external key as the additional layer of security so an attacker would require 2 pieces, the hash and the key.

Or are you suppose to use this then the salt in addition?

All the attacker has to do is run the .match with a password if they obtain the hash

BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
String password = ... // Password entered by user
String dbPassword       = ... // Load hashed DB password

if (passwordEncoder.matches(password, dbPassword)) {

}

But with a key not stored in the hash an attacker wouldn't be able to just run a decoder against a string they'd need the external key. So how is this more secure than using an external key?

el_pup_le
  • 11,711
  • 26
  • 85
  • 142
  • [**bcrypt**](https://en.wikipedia.org/wiki/Bcrypt) is a *hashing* function. There is no "decode" algorithm. That's why it's secure. Closing as duplicate explaining difference between hashing (no decode) and encrypting (can decode). – Andreas May 09 '18 at 02:19
  • ok its secure but would this be considered hashed + salted or just a hashed password? – el_pup_le May 09 '18 at 02:23
  • Are you supplying a salt value? No? Then it's not salted. – Andreas May 09 '18 at 02:26
  • ok i was confused because i read this stores a salt and i googled hashing + salting passwords – el_pup_le May 09 '18 at 02:28
  • mmmmmmmmmm salt – el_pup_le May 09 '18 at 02:49
  • @Andreas The linked answer does not answer the question: "BCryptPasswordEncoder here and I don't understand why this would be used rather than a hash+salt", the question does not ask about password encryption, it asked about `BCryptPasswordEncoder` vs hashing with a salt. The linked question is about password encryption vs hashing. – zaph May 09 '18 at 06:32
  • The main difference between `BCryptPasswordEncoder` and a simple hash such as SHA-256 is iteration. The iteration means that a substantial amount of CPU time must be consumed, generally around 100ms. This makes it about 10,000 times slower to perform a brute force attack. – zaph May 09 '18 at 06:45
  • @zaph The question was changed. See [edit history](https://stackoverflow.com/posts/50244571/revisions). It used to say *"BCryptPasswordEncoder here and I don't understand how this is considered secure"*, to which the answer is that it's secure because it's a hashing function, not an encryption function. OP was unaware that bcrypt is hashing, which is why OP said *"all it takes to for an attacker to crack it is gaining access to the hash and using the algorithm's decode"*, which of course makes no sense, since hashing functions don't have a "decode" algorithm. – Andreas May 09 '18 at 17:02
  • @Andreas The problem is that you closed it as a duplicate and the answer linked to no longer answers the question. Consider fixing that or at least reopen. – zaph May 09 '18 at 22:34

0 Answers0