3

Since version 1.61, the BouncyCastle library supports the Argon2 password based key derivation function. However, I cannot find an example how to use the Argon2 algorithm through the BouncyCastle API. Can someone give a hint? Thanks a lot.

haui
  • 567
  • 5
  • 18
  • 3
    Take a look at class `org.bouncycastle.crypto.test.Argon2Test` in the source code distro for bouncycastle 1.61 – President James K. Polk Apr 28 '19 at 20:33
  • Thanks @JamesKPolk. Am I right that there is no "official" API in javax.crypto for a password based key derivation functions, where something like "argon2" can be used als algorithm name? So one has to explicitly use the `org.bouncycastle.crypto.params.Argon2Parameters` classes, right? – haui Apr 29 '19 at 13:50

1 Answers1

7

If you look for an example, you can look into the Spring Security source code on GitHub, because Spring Security Crypto uses BouncyCastle for Argon2 password hashing.

If you just want to use a library for Argon2 password encryption, you could also use Spring Security Crypto (has only 2 optional compile dependencies).

Argon2PasswordEncoder argon2PasswordEncoder = new Argon2PasswordEncoder();
String aCryptedPassword = argon2PasswordEncoder.encode("password");
boolean passwordIsValid = argon2PasswordEncoder.matches("password", aCryptedPassword);
BuZZ-dEE
  • 6,075
  • 12
  • 66
  • 96