Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.security.NoSuchProviderException: no such provider: BC

I am using AdvancedInstaller 9.8 to build my javacode (webapplication) to an installer. Normally my application is running fine. After creating my installer with Advanced Installer 9.8, the installer size is around 55 MB. But there is an option in advanced installer to compress all the jars made for the installation. If i compress the jars, the installer size is around 16 MB. But when I compress with Advanced Installer 9.8, I am getting the exception (as mentioned in the title) when executing the line KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "BC"); in my code. Again the KeyPairGenerator is from the package java.security.*;

Could anybody please let me know, what could be the cause of this issue. I know when compressing with AdvancedInstaller, it could be some issue with the Advanced Installer compressing. But my question is what could be normally the issue on java side, to get that issue. ( i mean what could be the reason, like any file can be corrupted (or) etc any other reasons) so that I can start working from there.

like image 608
ssaitala Avatar asked Jan 25 '13 06:01

ssaitala


3 Answers

Add this line before your code:

Security.addProvider(new BouncyCastleProvider());
like image 62
mohamed Avatar answered Nov 15 '22 17:11

mohamed


You can add security provider by editing java.security with using following code with creating static block:

static {
    Security.addProvider(new BouncyCastleProvider());
}

If you are using maven project, then you will have to add dependency for BouncyCastleProvider as follows in pom.xml file of your project.

<dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcprov-jdk15on</artifactId>
            <version>1.47</version>
</dependency>

If you are using normal java project, then you can add download bcprov-jdk15on-147.jar from the link given below and edit your classpath.

http://www.java2s.com/Code/Jar/b/Downloadbcprovextjdk15on147jar.htm

like image 25
Krutik Avatar answered Nov 15 '22 18:11

Krutik


It got fixed by replacing the latest bcprov-jdk15-.jar. My previous version is bcprov-jdk15-135.jar and it created the problem as mentioned above.

like image 3
ssaitala Avatar answered Nov 15 '22 18:11

ssaitala