I'm trying to use Apache Commons Crypto library. I'm using example code from apache official site for using Random API of this lib. Here is the link to it - https://commons.apache.org/proper/commons-crypto/xref-test/org/apache/commons/crypto/examples/RandomExample.html
And I get this exception when using method 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
Process finished with exit code 1
How to solve this issue?
As far as I understand the proble is with loading openSSL engine or something like that:
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)