0

We use bouncy castle for encryption. We do not have any problem when we laucn our code in debug mode in Eclipse but when we manually launch the JAR we have a NoSuchAlgorithmException. The JAR is built using the maven plugin configuration

<dependencies>
    <dependency>
        <groupId>org.bouncycastle</groupId>
        <artifactId>bcprov-jdk15on</artifactId>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <createDependencyReducedPom>false</createDependencyReducedPom>
                        <minimizeJar>false</minimizeJar>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Here is our code :

Security.insertProviderAt(new BouncyCastleProvider(), 1);
Cipher cipher = Cipher.getInstance("RSA/None/OAEPWithSHA256AndMGF1Padding");
cipher.init(Cipher.DECRYPT_MODE, privateKey);
return cipher.doFinal(data);

We have changed the security policy to the unlimited one given by Oracle but the problem still remains. Any ideas?

Maxim
  • 52,561
  • 27
  • 155
  • 209
Antelop
  • 157
  • 11
  • The answer is in an other post, see http://stackoverflow.com/questions/36329068/bouncycastle-error-jce-cannot-authenticate-the-provider-bc-with-jar-with-depe – Antelop Mar 16 '17 at 15:59
  • using spring boot plugin instead of shade plugin solved the problem – Antelop Mar 16 '17 at 16:20
  • A solution is to add Bouncy Castle provider to the JRE java.security provider, the Bouncy Castle JAR in the JRE external libraries and exclude it from the JAR. But it is a pain when dealing with multiple deployments. Is there an other solution ? – Antelop Mar 16 '17 at 15:48

0 Answers0