I am trying to use Argon2 to hash a password however I keep getting an UnsatifiedLinkError. I believe my pom.xml dependencies are correct but It seems like the library cannot be found.
I tried manually loading the library (System.loadLibrary) but that did not work either.
Has anyone run into this? I would greatly appreciate the help.
I am using Intellij on a Mac M1.
import de.mkammerer.argon2.Argon2;
import de.mkammerer.argon2.Argon2Factory;
/* used for keystore*/
public class Argon {
/**
* This method calculates/returns an Argon2 hash from the users password
*
* @param iterations Total number of iterations
* @param memory Memory usage in kibibytes
* @param parallelism Number of threads used for hash computation
* @param password User password
* @return password hash
*/
String getHash(int iterations, int memory, int parallelism, char[] password) {
// Create a default instance of Argon2
Argon2 argon2 = Argon2Factory.create();
// Instantiate password hash String
String passwordHash = "";
// Generate the hash from the user's password.
try {
passwordHash = argon2.hash(iterations, memory, parallelism, password);
} finally {
// Wipe confidential data
argon2.wipeArray(password);
}
return passwordHash;
}
/**
* This method compares the hash of the correct password (From the Keystore) to the hash of a password entered by
* the user. It verifies the password hash against the correct hash and returns a boolean result.
*
* @param keyStoreHash Hash of correct password from Keystore
* @param password User entered password
* @return Boolean result of the comparison.
*/
boolean verifyPassword(String keyStoreHash, String password) {
// Create a default instance of Argon2
Argon2 argon2 = Argon2Factory.create();
try {
/** If the password hash matches the Argon2 hash, then return true,
else, return false. */
if (argon2.verify(keyStoreHash, password.toCharArray())) {
System.out.println("\n\nHash matches password.");
return true;
} else {
System.out.println("\n\nHash does NOT matches password.");
return false;
}
} finally {
// Wipe confidential data
argon2.wipeArray(password.toCharArray());
}
}
public static void main(String[] args) {
Argon testArgon = new Argon();
char[] pass = "test".toCharArray();
System.out.println(testArgon.getHash(10,65536,1,pass));
}
}