cannot find javax.crypto.KeyGeneratorSpi

The following code compiles but

I get a runtime error as follows.

NoClassDefFoundError for javax.crypto.KeyGeneratorSpi

I did a jar tf on the sunjce_provider.jar file and

this class is not contained?

It is in the jce1_2_1.jar file and is abstract.

When at runtime the factory tries to create an instance

of the keyGeneratorSpi I think it tries to get a concrete

implementation of the class from the SunJCE implementation and cant find it?

Is this correct.

Obviously the classpath is set correct as I am able to

import all of the SunJCE classes.

Heres the code.

import java.io.*;

import java.util.*;

import javax.crypto.*;

import javax.crypto.spec.*;

import com.sun.crypto.provider.*;

import java.security.*;

public class CryptoTest {

public static void main(String[] args)

{

KeyGenerator keygen= null;

SecretKeydesKey= null;

CipherdesCipher = null;

Security.addProvider( new com.sun.crypto.provider.SunJCE() );

byte[] ciphertext;

try

{

keygen = KeyGenerator.getInstance("DES","SunJCE");

}

catch(Exception e){

System.out.println("Exception getting keygenerator");

e.printStackTrace();

}

}

}

[1335 byte] By [tonydonohoe] at [2007-9-26 2:42:18]
# 1

What jdk version do you use?

I use the J2SDK 1.4.0-beta(contains the jce and the Sun JCE provider).

And the following code works fine to me:

KeyGenerator keygen = null;

try {

keygen = KeyGenerator.getInstance("DES","SunJCE");

} catch(Exception e) {

System.out.println("Exception getting keygenerator");

e.printStackTrace();

}

uwe_guenther at 2007-6-29 10:19:10 > top of Java-index,Security,Cryptography...