Trying to write a Provider

CAllen@symantec.com
Wed, 15 Jul 1998 10:44:33 -0700

From: CAllen@symantec.com
Date: Wed, 15 Jul 1998 10:44:33 -0700
Subject: Trying to write a Provider
To: java-security@java.sun.com

I am trying to write my own cryptographic provider, but I am having
trouble getting objects out of it.

For instance, when I try to get a KeyGenerator object using the static
getInstance() method, I get the following exception:

NoSuchAlgorithmException
class configured for KeyGenerator:
allenProvider.security.XORKeyGenerator not a KeyGenerator

I get a similar error when I use the getInstance() method to get a
Cipher object.

I am pretty darn sure that my KeyGenerator, and its KeyGeneratorSpi,
extend and implement the correct objects. The files compile just fine
(which may not mean much).

Being the curious sort, I searched the java source code for this error
message, and found the following snippet in the Security.java file:

static Object[] getImpl(String algorithm, String type, String
provider)
throws NoSuchAlgorithmException, NoSuchProviderException {

ProviderProperty classImpl = getEngineClassName(algorithm, provider,
type);
String className = classImpl.property;

try {

Class typeClass = Class.forName("java.security." + type + "Spi");
Class cl = Class.forName(className);

if (checkSuperclass(cl, typeClass)) {
Object obj = cl.newInstance();
return new Object[] { obj, classImpl.provider };
} else {
throw new NoSuchAlgorithmException("class configured for " +
type + ": " +
className +
" not a " + type);
}

If I am reading this correctly, then to get an instance of something,
the object has to be a subclass of something in the java.security
package. However, KeyGenerator and Cipher are in the javax.crypto
package, so I do not see any way to get this to work.

However, the DES cipher works just fine, even though it comes with the
javax.crypto package, so I know that you can use other packages.

The "How to implement a Provider" document does not mention a solution
for this, as far as I can tell.

Now, I am probably missing something really obvious, but I cannot
figure out what it is. Do you have any solutions that I can try? I can
send you the source code if you need it.

Chris Allen
callen@symantec.com