Crysfel
Crysfel

Reputation: 8158

Cryptography - RSA Algorithm in Java 1.4

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.

Upvotes: 2

Views: 3536

Answers (2)

Eadwacer
Eadwacer

Reputation: 1138

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());
}

Upvotes: 2

Jherico
Jherico

Reputation: 29240

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

Upvotes: 2

Related Questions