org.springframework.security.crypto.argon2.Argon2PasswordEncoder Java Examples

The following examples show how to use org.springframework.security.crypto.argon2.Argon2PasswordEncoder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Argon2Example.java    From code-examples with MIT License 6 votes vote down vote up
public String encode(String plainPassword) {
  int saltLength = 16; // salt length in bytes
  int hashLength = 32; // hash length in bytes
  int parallelism = 1; // currently is not supported
  int memory = 4096; // memory costs
  int iterations = 3;

  Argon2PasswordEncoder argon2PasswordEncoder =
      new Argon2PasswordEncoder(saltLength, hashLength, parallelism, memory, iterations);
  return argon2PasswordEncoder.encode(plainPassword);
}
 
Example #2
Source File: SecurityConfiguration.java    From code-examples with MIT License 5 votes vote down vote up
@Bean
public PasswordEncoder passwordEncoder() {
  // we must use deprecated encoder to support their encoding
  String encodingId = "bcrypt";
  Map<String, PasswordEncoder> encoders = new HashMap<>();
  encoders.put(encodingId, new BCryptPasswordEncoder(bcCryptWorkFactorService.calculateStrength()));
  encoders.put("ldap", new LdapShaPasswordEncoder());
  encoders.put("MD4", new Md4PasswordEncoder());
  encoders.put("MD5", new MessageDigestPasswordEncoder("MD5"));
  encoders.put("noop", NoOpPasswordEncoder.getInstance());
  encoders.put("pbkdf2", new Pbkdf2PasswordEncoder());
  encoders.put("scrypt", new SCryptPasswordEncoder());
  encoders.put("SHA-1", new MessageDigestPasswordEncoder("SHA-1"));
  encoders.put("SHA-256", new MessageDigestPasswordEncoder("SHA-256"));
  encoders.put("sha256", new StandardPasswordEncoder());
  encoders.put("argon2", new Argon2PasswordEncoder());

  return new DelegatingPasswordEncoder(encodingId, encoders);
}
 
Example #3
Source File: SecurityConfig.java    From springsecuritytotp with MIT License 4 votes vote down vote up
@Bean
public PasswordEncoder passwordEncoder() {
  return new Argon2PasswordEncoder(16, 32, 8, 1 << 16, 4);
}