jce cannot authenticate the provider bc

2019-03-02 09:32发布

问题:

I have developed an application in which I have used the Cryptography with the help of BountyCastle.jar. I also had a line Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());

Everything works fine when I execute the program from Netbeans

But when I packaging the application in an executable jar which internally uses BouncyCastle jar and execute the jar,

I am getting exception

JCE cannot authenticate the provider BC java.lang.SecurityException: JCE cannot authenticate the provider BC

Is there any other approch to implement the same. Because it is difficult for non technical person to add BountyCastle.jar in ext folder of jre. so is there any other method to solve my problem.

Is there any method to exclude BountyCastle.jar while packaging jar in netbeans so that will accessible from external lib folder.

回答1:

The BouncyCastle jar archive is signed by BouncyCastle to prevent unauthorized changes. It needs the JCA signature in order to be trusted as a cryptography provider, so do not remove it.

See a related post



回答2:

Don't add the class to your fat/assembly jar created by mvn/sbt. Make it provided. Download the jars from the official web page and add the jar separately to classpath of your program.