java.security.NoSuchProviderException: no such pro

2020-07-09 01:48发布

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.

5条回答
smile是对你的礼貌
2楼-- · 2020-07-09 02:11

The problem can be resolved by importing the following:

import org.bouncycastle.jce.provider.BouncyCastleProvider;

Then put the below code in your class method:

Security.addProvider(new BouncyCastleProvider());
查看更多
家丑人穷心不美
3楼-- · 2020-07-09 02:20

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

查看更多
爷、活的狠高调
4楼-- · 2020-07-09 02:23

Add this line before your code:

Security.addProvider(new BouncyCastleProvider());
查看更多
手持菜刀,她持情操
5楼-- · 2020-07-09 02:29

Along with checking jre configuration you will need to check

1.Check that the java home is set in the configuration

2.Check which java environment is used for application

3.Check that \jre\lib\security\java.security has bouncycastle provider entry. i.e. security.provider.9=org.bouncycastle.jce.provider.BouncyCastleProvider

4.Also check that bouncy castle jar is added to \jre\lib\ext\ bcprov-jdk15on-147.jar (latest one to work for java 1.5 & 1.6

查看更多
我欲成王,谁敢阻挡
6楼-- · 2020-07-09 02:34

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.

查看更多
登录 后发表回答