我正在处理一个需要使用.so库(ubuntu18.04)的项目,当我将java代码放入/src文件夹(我使用IntelliJ的想法)时,一切都运行良好,但是当我将代码移动到一个命名的包(Smutil)之后,它会导致一些错误,比如“线程中的异常”主“java.lang.UnsatisfiedLinkError: smutil.GmSSL.digest(Ljava/lang/String;[b)”[B“)。
这是我的密码
package smutil;
public class GmSSL {
public native String[] getVersions();
public native String[] getCiphers();
public native String[] getDigests();
public native String[] getMacs();
public native String[] getSignAlgorithms();
public native String[] getPublicKeyEncryptions();
public native String[] getDeriveKeyAlgorithms();
public native byte[] generateRandom(int length);
public native int getCipherIVLength(String cipher);
public native int getCipherKeyLength(String cipher);
public native int getCipherBlockSize(String cipher);
public native byte[] symmetricEncrypt(String cipher, byte[] in, byte[] key, byte[] iv);
public native byte[] symmetricDecrypt(String cipher, byte[] in, byte[] key, byte[] iv);
public native int getDigestLength(String digest);
public native int getDigestBlockSize(String digest);
public native byte[] digest(String algor, byte[] data);
public native String[] getMacLength(String algor);
public native byte[] mac(String algor, byte[] data, byte[] key);
public native byte[] sign(String algor, byte[] data, byte[] privateKey);
public native int verify(String algor, byte[] digest, byte[] signature, byte[] publicKey);
public native byte[] publicKeyEncrypt(String algor, byte[] in, byte[] publicKey);
public native byte[] publicKeyDecrypt(String algor, byte[] in, byte[] privateKey);
public native byte[] deriveKey(String algor, int keyLength, byte[] peerPublicKey, byte[] privateKey);
public native String[] getErrorStrings();
static {
System.loadLibrary("gmssljni");
}
}发布于 2019-06-15 09:40:11
您可能会将.so文件打包到JAR中。请注意,一旦您有了.so,加载库就不那么容易了。
为了加载共享库,您必须确保它在文件系统上。您可以通过将其提取到临时位置来克服此问题。
在这里查看一个完整的示例,说明这个主题:
https://github.com/mkowsiak/jnicookbook/tree/master/recipes/recipeNo031
基本上,你要做的是:
System.load(fullPathToFile)(就是这样:)
和JNI玩得开心!
https://stackoverflow.com/questions/56607165
复制相似问题