views:

74

answers:

2

Hi folks!

I am using Java 1.4.2_10 and I am trying to use RSA encryption:

I am getting the NoSuchAlgorithmException for the following code:

cipher = Cipher.getInstance("RSA");

This is the error:

java.security.NoSuchAlgorithmException: Cannot find any provider supporting RSA
        at javax.crypto.Cipher.getInstance(DashoA6275)

This works fine in 1.5 and above, however I need to use 1.4. Is there any workaround or thirdparty product that I can use to fix this?

Thanks in advance.

+2  A: 

You can install the Bouncy Castle cryptography provider. Just grab their jars and then call Cipher.getInstance("RSA", "BC")

Jherico
And tell `java.security.Security` somehow to use the provider. Documentation for Bouncy Castle isn't always easy to find, so here's one way to do it: `Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());` (maybe there are alternative ways?)
Chris Lercher
Thank you for you answers! but now I'm getting this error:"java.lang.SecurityException: The provider BC may not be signed by a trusted party at javax.crypto.SunJCE_b.a(DashoA12275)"I downloaded the "bcprov-jdk14-145.jar" from the official website, it suppose to be signed. Am I missing something? thanks again!
Stock
+1  A: 

Java 1.4 definitely supports RSA, so the fact that this isn't working suggests that something deeper is wrong. Does this work with any other ciphers (such as "AES" or "DES")? You should check to make sure your providers are properly configured. What is the output of the following code on your system:

System.out.println("Providers: ");
java.security.Provider[] providers =  java.security.Security.getProviders();
for(int x = 0; x < providers.length; x++) {
    System.out.println("\t" + providers[x]);
}

System.out.println();
System.out.println("Algorithms: ");
java.util.Set algs = java.security.Security.getAlgorithms("Cipher");

java.util.Iterator i_algs = algs.iterator(); 
while(i_algs.hasNext()) {
    System.out.println("\t" + i_algs.next());
}
Eadwacer