liveBook · Manning

Pbkdf2

As explained in Spring Security in Action, Second Edition

PBKDF2 is a password-based key-derivation standard that repeatedly applies a pseudorandom function to derive a cryptographic key from a password and salt.

PBKDF2 is a Spring Security password encoder based on the password-based key derivation function 2. It provides a stronger password-hashing option than the deprecated StandardPasswordEncoder, which uses SHA-256. section 4.1.3

PasswordEncoder p = 
  new Pbkdf2PasswordEncoder("secret", 16, 310000, Pbkdf2PasswordEncoder. SecretKeyFactoryAlgorithm.PBKDF2WithHmacSHA256);

Configure a Pbkdf2PasswordEncoder with a secret, salt length, iteration count, and PBKDF2WithHmacSHA256 algorithm. section 4.1.3

Spring Security provides several password-encoder choices:

  • Use Pbkdf2PasswordEncoder for PBKDF2-based password encoding. section 4.1.3
  • Contrast it with BCryptPasswordEncoder and SCryptPasswordEncoder; avoid NoOpPasswordEncoder in real-world applications. section 4.1.3

How Spring Security in Action, Second Edition covers it

How deep it goes
Shows the implementation choice and configurable constructor, but does not explain PBKDF2 internals.
Examples
Uses a Pbkdf2PasswordEncoder configured with a secret, 16-byte salt, 310000 iterations, and PBKDF2WithHmacSHA256.
What you can do after
Configure it through Spring Security's Pbkdf2PasswordEncoder constructor.
How it connects
Connects PBKDF2 with PasswordEncoder, BCrypt, SCrypt, SHA-256, and cleartext password handling.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Security in Action, Second Edition. The section links point to the parts of the book it draws on.