16

What's the best way to integrate the Bouncy Castle provider in a Java program? I know I can add it programmatically, by using:

import org.bouncycastle.jce.provider.BouncyCastleProvider;
...
Security.addProvider(new BouncyCastleProvider());

Or either I can add it to a path in the JRE on my machine.

What's the best choice?

Ram
  • 3,092
  • 10
  • 40
  • 56
Pablosproject
  • 1,374
  • 3
  • 13
  • 33

1 Answers1

11

In my opinion the adding it as security provider with own code is the best option. This is because it is only project dependent - not system dependent. Add the BouncyCastle jar file(s) to your project and add them to the class-path and that's it. It will work on all systems without need for further manual installation steps.

If you install BouncyCastle into the JRE you always have problems in case you have to update the JRE.

Robert
  • 39,162
  • 17
  • 99
  • 152
  • How I can add the jar to the class-path under Eclipse?? – Pablosproject Jun 23 '11 at 09:05
  • 4
    Create in your project a directory named "lib", copy the JAR file in it and then select from the JAR file's context menu "Build Path" -> "Add to Build Path" – Robert Jun 23 '11 at 12:40
  • If you embed BC jar into your own, the signatures won't match, and you get an "java.lang.SecurityException: Invalid signature file digest for Manifest" error. In which case this https://stackoverflow.com/questions/25842559/valid-jar-signature-for-javafx-projects/30922181#30922181 helps (disclosure: shameless plug of my own answer) – foo Jul 24 '19 at 15:57