简体   繁体   English

使用Apache Crypto Commons时java.security.GeneralSecurityException CryptoCipher

[英]java.security.GeneralSecurityException CryptoCipher when using Apache Crypto Commons

I'm attempting to use the code here for encryption https://commons.apache.org/proper/commons-crypto/xref-test/org/apache/commons/crypto/examples/CipherByteArrayExample.html . 我正在尝试在此处使用代码进行加密https://commons.apache.org/proper/commons-crypto/xref-test/org/apache/commons/crypto/examples/CipherByteArrayExample.html I copied the code word-for-word and I am not sure why I'm getting this exception as I can't find much on the issue. 我逐字复制了代码,但我不确定为什么会遇到这个异常,因此我不确定为什么会出现此异常。 The only part that I changed was "StandardCharsets.UTF_8" to the String "UTF-8." 我更改的唯一部分是将“ StandardCharsets.UTF_8”更改为字符串“ UTF-8”。 I am also not interested in using Bouncy Castle or the java JCE as alternatives but am open to other libraries that use AES/DES in CBC/ECB modes (I am aware of the dangers of DES/ECB so no need for the lecture). 我也对使用Bouncy Castle或java JCE作为替代品不感兴趣,但是对其他在CBC / ECB模式下使用AES / DES的库开放(我知道DES / ECB的危险,因此无需上课)。 Thank you. 谢谢。

EDIT: 编辑:

Stack trace (Note that line 62 of Crypto.java is "CryptoCipher encipher=Utils.getCipherInstance(transform, properties) ): 堆栈跟踪(请注意,Crypto.java的第62行是“ CryptoCipher encipher = Utils.getCipherInstance(transform,properties)):

    W/System.err: java.io.IOException: java.security.GeneralSecurityException: CryptoCipher {org.apache.commons.crypto.cipher.OpenSslCipher} is not available or transformation AES/CBC/PKCS5Padding is not supported.
                  at org.apache.commons.crypto.utils.Utils.getCipherInstance(Utils.java:130)
                  at com.example.me.cryptotest.Crypto.test(Crypto.java:62)
                  at com.example.me.cryptotest.MainActivity.onCreate(MainActivity.java:43)
                  at android.app.Activity.performCreate(Activity.java:7009)
                  at android.app.Activity.performCreate(Activity.java:7000)
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
    W/System.err: 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
                  at android.app.ActivityThread.-wrap11(Unknown Source:0)

    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
                  at android.os.Handler.dispatchMessage(Handler.java:106)
                  at android.os.Looper.loop(Looper.java:164)
                  at android.app.ActivityThread.main(ActivityThread.java:6494)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
              Caused by: java.security.GeneralSecurityException: CryptoCipher {org.apache.commons.crypto.cipher.OpenSslCipher} is not available or transformation AES/CBC/PKCS5Padding is not supported.
                  at org.apache.commons.crypto.cipher.CryptoCipherFactory.getCryptoCipher(CryptoCipherFactory.java:176)

    at org.apache.commons.crypto.utils.Utils.getCipherInstance(Utils.java:128)
                ... 15 more

    W/System.err: Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
                  at org.apache.commons.crypto.utils.ReflectionUtils.newInstance(ReflectionUtils.java:90)
                  at org.apache.commons.crypto.cipher.CryptoCipherFactory.getCryptoCipher(CryptoCipherFactory.java:160)
                ... 16 more
              Caused by: java.lang.reflect.InvocationTargetException
                  at java.lang.reflect.Constructor.newInstance0(Native Method)
                  at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
        W/System.err:     
at     org.apache.commons.crypto.utils.ReflectionUtils.newInstance(ReflectionUtils.java:88)
                ... 17 more

    Caused by: java.lang.RuntimeException: java.lang.RuntimeException: no native library is found for os.name=Linux and os.arch=x86
                  at org.apache.commons.crypto.cipher.OpenSslCipher.<init>(OpenSslCipher.java:59)
                ... 20 more
              Caused by: java.lang.RuntimeException: no native library is found for os.name=Linux and os.arch=x86
                  at org.apache.commons.crypto.NativeCodeLoader.findNativeLibrary(NativeCodeLoader.java:120)
                  at org.apache.commons.crypto.NativeCodeLoader.loadLibrary(NativeCodeLoader.java:62)
                  at org.apache.commons.crypto.NativeCodeLoader.<clinit>(NativeCodeLoader.java:50)
                  at org.apache.commons.crypto.NativeCodeLoader.isNativeCodeLoaded(NativeCodeLoader.java:261)
                  at org.apache.commons.crypto.Crypto.isNativeCodeLoaded(Crypto.java:84)
W/System.err:     at org.apache.commons.crypto.cipher.OpenSsl.<clinit>(OpenSsl.java:94)
                  at org.apache.commons.crypto.cipher.OpenSsl.getLoadingFailureReason(OpenSsl.java:114)
                  at org.apache.commons.crypto.cipher.OpenSslCipher.<init>(OpenSslCipher.java:57)
                ... 20 more

I see your problem here: 我在这里看到您的问题:

java.lang.RuntimeException: no native library is found for os.name=Linux and os.arch=x86

Looks like you are not using Oracle JVM. 看起来您没有使用Oracle JVM。 Possible your JVM is reporting different os.arch string then standard Oracle JVM, so you need to copy the native library from possibly linux/i386 to linux/x86 (wild guess). 可能是您的JVM报告的是不同于标准Oracle JVM的os.arch字符串,因此您需要将本机库从可能的linux/i386复制到linux/x86 (很自然的猜测)。 Fire a google search on this error no native library is found for os.name=Linux and os.arch=x86 , and playaround with your OS & JVM to help your runtime find the required native library(s). 针对此错误no native library is found for os.name=Linux and os.arch=x86 Google搜索, no native library is found for os.name=Linux and os.arch=x86 ,并使用OS和JVM进行播放以帮助您的运行时查找所需的本机库。

Update: If you look at the `README.md' of the project on github . 更新:如果您在github上查看项目的`README.md'。 You will notice this: 您会注意到:

Portable across various operating systems (currently only Linux/MacOSX/Windows); Apache Commons Crypto loads the library according to your machine environment (it checks system properties, os.name and os.arch).

And this is the dll structure they have in the code, 这就是他们代码中的dll结构,

在此处输入图片说明

so you can override your System property 'os.arch' to load the native library as per your OS: 因此您可以覆盖您的系统属性'os.arch'以根据您的操作系统加载本机库:

System.setProperty("os.arch", "@folder")

Just for reference, I am running the code in Windows 10 with Oracle JDK8, so my derived path is coming to /org/apache/commons/crypto/native/Windows/x86_64/commons-crypto.dll 仅供参考,我在Windows 10中使用Oracle JDK8运行代码,因此我的派生路径位于/org/apache/commons/crypto/native/Windows/x86_64/commons-crypto.dll

Hope this will provide you more help in resolving the issue. 希望这将为您解决问题提供更多帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Apache Commons在Java中下载文件时获取HTTP 302 - Getting HTTP 302 when downloading file in Java using Apache Commons 使用Apache Commons lineIterator时出现OutOfMemory错误 - OutOfMemory error when using Apache Commons lineIterator 使用java apache commons下载文件? - Download file using java apache commons? Java:使用Apache Commons CLI 1.2的NoClassDefFoundError - Java: NoClassDefFoundError using Apache Commons CLI 1.2 在Java中使用Apache Commons Optimize()的问题 - Issue using apache commons optimize() in java 使用 Apache Commons Math 在 Java 中进行优化 - Optimisation in Java Using Apache Commons Math 使用 Java 反射时出现 `java.lang.ClassNotFoundException: org.apache.commons.pool.PoolableObjectFactory` - Getting `java.lang.ClassNotFoundException: org.apache.commons.pool.PoolableObjectFactory` when using Java reflection 调用CommandLineParser#parser时使用org.apache.commons.cli的java.lang.IllegalAccessError - java.lang.IllegalAccessError using org.apache.commons.cli when calling CommandLineParser#parser 在Java中,在发送JSON POST时使用HttpPost(apache commons HttpClient) - 我应该对身体进行URL编码吗? - In Java, using HttpPost (apache commons HttpClient) when sending JSON POST - should I URL encode the body? Java Apache Commons用户 - Java Apache Commons users
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM