[英]Exception in thread “main” java.lang.UnsatisfiedLinkError: Unable to load library
[英]Why do I get: Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'argon2':
我正在尝试使用 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));
}
}
我撒谎了,这是 pom 依赖。
由此:
<dependency>
<groupId>de.mkammerer</groupId>
<artifactId>argon2-jvm-nolibs</artifactId>
<version>2.11</version>
</dependency>
对此:
<dependency>
<groupId>de.mkammerer</groupId>
<artifactId>argon2-jvm</artifactId>
<version>2.11</version>
</dependency>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.