Pbkdf2PasswordEncoder allows custom SecretKeyFactory

Fixes gh-2742
This commit is contained in:
Rob Winch
2017-10-24 08:34:30 -05:00
parent b91aa19b35
commit fe8f3afbaf
2 changed files with 54 additions and 4 deletions

View File

@@ -75,6 +75,23 @@ public class Pbkdf2PasswordEncoderTests {
assertThat(fixedHex).isEqualTo(encodedPassword);
}
@Test
public void encodeAndMatchWhenSha256ThenSuccess() {
this.encoder.setAlgorithm(Pbkdf2PasswordEncoder.SecretKeyFactoryAlgorithm.PBKDF2WithHmacSHA256);
String rawPassword = "password";
String encodedPassword = this.encoder.encode(rawPassword);
assertThat(this.encoder.matches(rawPassword, encodedPassword)).isTrue();
}
@Test
public void matchWhenSha256ThenSuccess() {
this.encoder.setAlgorithm(Pbkdf2PasswordEncoder.SecretKeyFactoryAlgorithm.PBKDF2WithHmacSHA256);
String rawPassword = "password";
String encodedPassword = "821447f994e2b04c5014e31fa9fca4ae1cc9f2188c4ed53d3ddb5ba7980982b51a0ecebfc0b81a79";
assertThat(this.encoder.matches(rawPassword, encodedPassword)).isTrue();
}
/**
* Used to find the iteration count that takes .5 seconds.
*/
@@ -105,4 +122,4 @@ public class Pbkdf2PasswordEncoderTests {
}
System.out.println("Iterations " + iterations);
}
}
}