Tag Archives: java.security.NoSuchProviderException error

java.security.NoSuchProviderException: no such provider: BC [Two Method]

Method 1:

1. Modify the following two files

%JDK_Home%\jre\lib\security\java.security

%JRE_Home%\jre\lib\security\java.security

Append the last line

security.provider.1=sun.security.provider.Sun
security.provider.2=sun.security.rsa.SunRsaSign
security.provider.3=sun.security.ec.SunEC
security.provider.4=com.sun.net.ssl.internal.ssl.Provider
security.provider.5=com.sun.crypto.provider.SunJCE
security.provider.6=sun.security.jgss.SunProvider
security.provider.7=com.sun.security.sasl.Provider
security.provider.8=org.jcp.xml.dsig.internal.dom.XMLDSigRI
security.provider.9=sun.security.smartcardio.SunPCSC
security.provider.10=sun.security.mscapi.SunMSCAPI
security.provider.11=org.bouncycastle.jce.provider.BouncyCastleProvider

2. Put bcprov-ext-jdk16-143.jar into

%JDK_Home%\jre\lib\ext

%JRE_Home%\jre\lib\ext

Method 2:

1. Introduce the bcprov-ext-jdk16-1.46.jar package in the project

<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-ext-jdk16</artifactId>
<version>1.46</version>
<type>jar</type>
<scope>compile</scope>
</dependency>

2. Add a static block to the encryption class.

static{
try{
Security.addProvider(newBouncyCastleProvider());
}catch(Exceptione){
e.printStackTrace();
}
}