我正在尝试使用 Argon2 对密码进行哈希处理,但是我不断收到 UnsatifiedLinkError。我相信我的 pom.xml 依赖项是正确的,但似乎找不到该库。
我尝试手动加载库(System.loadLibrary),但这也不起作用。
有没有人遇到过这个?我将非常感谢您的帮助。
我在 Mac M1 上使用 Intellij。
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));
}
}