2

I am trying to use Bouncy Castle as a security provider in a Maven project. It seems to work fine in certain places in the codebase and works completely fine everywhere for some people. However, if I try something like:

public class Foo {
    public static void main(String[] args) throws Exception {
        Signature signature = Signature.getInstance("SHA256withRSA", "BC");
    }
}

then I get a NoSuchProviderException exception.

In the pom I have Bouncy Castle as a dependency as

<dependency>
          <groupId>bouncycastle</groupId>
          <artifactId>bcprov-jdk16</artifactId>
          <version>140</version>
          <scope>compile</scope>
</dependency>

I have tried with several different JDKs and all give the same error.

nomel7
  • 1,523
  • 3
  • 12
  • 20

1 Answers1

4

As answered in this related SO question, adding the following line should solve your problem.

Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
Community
  • 1
  • 1
Raghuram
  • 51,854
  • 11
  • 110
  • 122
  • That fixed the problem but do you have any idea why it might work for some people and not for me even if they don't have that line? – nomel7 Jun 21 '12 at 18:00