Why java.security.NoSuchProviderException No such provider: BC?
Im not very familiar with the Android sdk, but it seems that the android-sdk
comes with the BouncyCastle
provider already added to the security.
What you will have to do in the PC environment is just add it manually,
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
if you have access to the policy
file, just add an entry like:
security.provider.5=org.bouncycastle.jce.provider.BouncyCastleProvider
Notice the .5
it is equal to a sequential number of the already added providers.
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
you can add security provider by editing java.security by adding security.provider.=org.bouncycastle.jce.provider.BouncyCastleProvider
or add a line in your top of your class
Security.addProvider(new BouncyCastleProvider());
you can use below line to specify provider while specifying algorithms
Cipher cipher = Cipher.getInstance("AES", "SunJCE");
if you are using other provider like Bouncy Castle then
Cipher cipher = Cipher.getInstance("AES", "BC");