java—使用cryptorandomfactory类的getcryptorandom方法时发生异常apache commons加密库

vlju58qv  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(311)

我正在尝试使用apachecommons加密库。我使用apache官方网站的示例代码来使用这个库的随机api。这是它的链接-https://commons.apache.org/proper/commons-crypto/xref-test/org/apache/commons/crypto/examples/randomexample.html
我在使用getcryptorandom方法时遇到了这个异常。

Exception in thread "main" java.security.GeneralSecurityException: CryptoRandom: [org.apache.commons.crypto.random.OpenSslCryptoRandom] failed with java.lang.reflect.InvocationTargetException
    at org.apache.commons.crypto.random.CryptoRandomFactory.getCryptoRandom(CryptoRandomFactory.java:217)
    at com.nix.apps.crypto.Main.main(Main.java:25)
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.random.CryptoRandomFactory.getCryptoRandom(CryptoRandomFactory.java:198)
    ... 1 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.apache.commons.crypto.utils.ReflectionUtils.newInstance(ReflectionUtils.java:88)
    ... 2 more
Caused by: java.security.GeneralSecurityException: Native library could not be initialised
    at org.apache.commons.crypto.random.OpenSslCryptoRandom.<init>(OpenSslCryptoRandom.java:88)
    ... 7 more
Caused by: java.lang.UnsatisfiedLinkError: ENGINE_load_rdrand
    at org.apache.commons.crypto.random.OpenSslCryptoRandomNative.initSR(Native Method)
    at org.apache.commons.crypto.random.OpenSslCryptoRandom.<clinit>(OpenSslCryptoRandom.java:56)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at org.apache.commons.crypto.utils.ReflectionUtils.getClassByNameOrNull(ReflectionUtils.java:138)
    at org.apache.commons.crypto.utils.ReflectionUtils.getClassByName(ReflectionUtils.java:103)
    at org.apache.commons.crypto.random.CryptoRandomFactory.getCryptoRandom(CryptoRandomFactory.java:197)
    ... 1 more

进程已完成,退出代码为1
如何解决这个问题?
据我所知,问题在于加载openssl引擎或类似的东西:

Caused by: java.lang.UnsatisfiedLinkError: ENGINE_load_rdrand
    at org.apache.commons.crypto.random.OpenSslCryptoRandomNative.initSR(Native Method)
    at org.apache.commons.crypto.random.OpenSslCryptoRandom.<clinit>(OpenSslCryptoRandom.java:56)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at org.apache.commons.crypto.utils.ReflectionUtils.getClassByNameOrNull(ReflectionUtils.java:138)
    at org.apache.commons.crypto.utils.ReflectionUtils.getClassByName(ReflectionUtils.java:103)
    at org.apache.commons.crypto.random.CryptoRandomFactory.getCryptoRandom(CryptoRandomFactory.java:197)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题