Why java.security.NoSuchProviderException There is no such provider: BC?

Added to the project jar (bcprov-jdk16-145.jar), Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()) added to the class, and BouncyCastleProvider.PROVIDER_NAME returns "BC", but AesFileIo.write still throws java.security.NoSuchProviderException No such provider: BC . Any ideas?

 import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.ObjectOutputStream; import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import org.bouncycastle.jce.provider.BouncyCastleProvider; public class AesFileIo { private static final String AES_ALGORITHM = "AES/CTR/NoPadding"; private static final String PROVIDER = BouncyCastleProvider.PROVIDER_NAME; private static final byte[] AES_KEY_128 = { // Hard coded for now 78, -90, 42, 70, -5, 20, -114, 103, -99, -25, 76, 95, -85, 94, 57, 54}; private static final byte[] IV = { // Hard coded for now -85, -67, -5, 88, 28, 49, 49, 85, 114, 83, -40, 119, -65, 91, 76, 108}; private static final SecretKeySpec secretKeySpec = new SecretKeySpec(AES_KEY_128, "AES"); private static final IvParameterSpec ivSpec = new IvParameterSpec(IV); public void AesFileIo() { Security.addProvider(new org.bouncycastle.jce.provider .BouncyCastleProvider()); } public void writeFile(String fileName, String theFile) { try { Cipher cipher = Cipher.getInstance(AES_ALGORITHM, PROVIDER); cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivSpec); byte[] encrypted = cipher.doFinal(theFile.getBytes()); ObjectOutputStream os = new ObjectOutputStream( new FileOutputStream(fileName)); os.write(encrypted); os.flush(); os.close(); } catch (Exception e) { StackTraceElement se = new Exception().getStackTrace()[0]; System.err.println(se.getFileName() + " " + se.getLineNumber() + " " + e); } } } 
+43
java security cryptography jce
Sep 14 '10 at 18:20
source share
4 answers

I am not very familiar with android sdk, but he sees that android-sdk comes with a BouncyCastle provider already added to security.

What you need to do in the PC environment, just add it manually,

 Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); 

if you have access to the policy file, just add an entry, for example:

 security.provider.5=org.bouncycastle.jce.provider.BouncyCastleProvider 

Note: .5 it is equal to the ordinal number of providers already added.

+87
Sep 14 '10 at 18:24
source share

you can add a security provider by editing java.security by adding security.provider. = org.bouncycastle.jce.provider.BouncyCastleProvider

or add a line to the top of your class

 Security.addProvider(new BouncyCastleProvider()); 

you can use the bottom line to indicate the provider when specifying the algorithms

 Cipher cipher = Cipher.getInstance("AES", "SunJCE"); 

if you use another provider, such as Bouncy Castle,

 Cipher cipher = Cipher.getInstance("AES", "BC"); 
+8
Oct. 15 '13 at
source share

You can add a security provider by editing java.security with the following code to create a static block:

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

If you are using a maven project , you will need to add a dependency for the BouncyCastleProvider , as indicated in the pom.xml file of your project.

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

If you are using a regular java project , you can add bcprov-jdk15on-147.jar from the link below and edit your classpath.

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

+3
Aug 01 '16 at 7:36
source share

For those who use web servers, make sure bcprov-jdk16-145.jar is installed on your lib servers, since weblogic should have put the jar in:

 <weblogic_jdk_home>\jre\lib\ext 
+1
Jun 05 '15 at 7:31
source share



All Articles