From: CAllen@symantec.com
Date: Thu, 16 Jul 1998 15:21:40 -0700
To: java-security@java.Sun.COM
Subject: Re[4]: Trying to write a Provider
--IMA.Boundary.7167260090
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Description: cc:Mail note part
I tried your suggestion about not extending Cipher and KeyGenerator, and I
already registered the Spi classes in the Provider subclass, but now I am
getting a different, but similar, error message; it is hard to tell, but it
looks like the provider is not able to find the algorithm.
Here is some sample code, with stuff like import statements and the
enciphering code removed; I do not think that has any affect on getting an
instance of the object. All of the classes are in the allen.security
package, and the files are in the right location.
The code compiles fine, but throws an exception at this line:
XORKeyGenerator xorKeyGenerator = getInstance("XOR", "Allen");
Here are the classes:
public final class AllenProvider extends Provider {
public AllenProvider() {
super("Allen", 1.0, "Allen's Cryptographic Provider");
put("Cipher.XOR", "allen.security.XOR");
put("KeyGenerator.XOR", "allen.security.XORKeyGenerator");
}
}
public final class XORKey implements SecretKey {
private byte[] key;
public XORKey(byte[] key) {
this.key = key;
}
public String getAlgorithm() {
return "XOR";
}
public byte[] getEncoded() {
return key;
}
public String getFormat() {
return "Any old format";
}
}
public final class XORKeyGeneratorSpi extends KeyGeneratorSpi {
SecureRandom secureRandom;
int strength;
public XORKeyGeneratorSpi() {
;
}
public SecretKey engineGenerateKey() {
// blah blah blah
return (SecretKey)key;
}
public void engineInit(int strength, SecureRandom secureRandom) {
this.strength = strength;
this.secureRandom = secureRandom;
}
public void engineInit(SecureRandom secureRandom) {
this.secureRandom = secureRandom;
}
public void engineInit(AlgorithmParameterSpec aps, SecureRandom
secureRandom) {
this.secureRandom = secureRandom;
}
public String toString() {
return "XOR";
}
}
public final class XORSpi extends javax.crypto.CipherSpi {
private XORKey xorKey;
private byte[] keyBytes;
private int keyStrength;
private int keyPosition;
private int mode;
private SecureRandom secureRandom;
public XORSpi() {
;
}
public int engineGetBlockSize() {
return 1;
}
public int engineGetOutputSize(int inputLen) {
return inputLen;
}
public byte[] engineGetIV() {
return null;
}
public void engineInit(int opmode, Key key, SecureRandom random)
throws InvalidKeyException {
// blah blah blah
}
public void engineInit(int opmode, Key key,
AlgorithmParameterSpec params,
SecureRandom random)
throws InvalidKeyException, InvalidAlgorithmParameterException {
// call the other engineInit method, and ignore the params
engineInit(opmode, key, random);
}
public byte[] engineUpdate(byte[] input, int inputOffset, int inputLen) {
byte[] output = new byte[input.length];
// blah blah blah
return output;
}
public int engineUpdate(byte[] input, int inputOffset, int inputLen,
byte[] output, int outputOffset)
throws ShortBufferException {
// blah blah blah
return inputLen;
}
public byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen)
throws IllegalBlockSizeException, BadPaddingException {
return engineUpdate(input, inputOffset, inputLen);
}
public int engineDoFinal(byte[] input, int inputOffset, int inputLen,
byte[] output, int outputOffset)
throws ShortBufferException, IllegalBlockSizeException,
BadPaddingException {
return engineUpdate(input, inputOffset, inputLen, output,
outputOffset);
}
public void engineSetMode(String mode) throws NoSuchAlgorithmException {
throw new NoSuchAlgorithmException("The XOR cipher does not support
modes.");
}
public void engineSetPadding(String padding) throws
NoSuchPaddingException {
throw new NoSuchPaddingException("The XOR cipher does not support
padding.");
}
}
I know this is a lot of code to look at, but there is probably something
simple I am forgetting to do. You were so quick to respond yesterday
(twice!) that I am hoping you can give me a little more help.
Thanks.
Chris Allen
callen@symantec.com
___________________ Reply Separator _________________________________
Subject: Re: Re[2]: Trying to write a Provider
Author: Jan Luehe <Jan.Luehe@Eng.Sun.COM> at Internet
Date: 7/15/98 1:36 PM
Chris:
Also, make sure that you register your provider's "Spi" classes in your
provider's master file.
Jan
> A call to "KeyGenerator.getInstance()" will have javax.crypto.JceSecurity
> create a javax.crypto.KeyGenerator object, and encapsulate your
> provider's implementation (which is a subclass of
javax.crypto.KeyGeneratorSpi)
> in it.
>
> Jan
>
--IMA.Boundary.7167260090
Content-Type: text/plain; charset=US-ASCII; name="RFC822 message headers"
Content-Transfer-Encoding: 7bit
Content-Description: cc:Mail note part
Content-Disposition: inline; filename="RFC822 message headers"
Received: from mailer.Symantec.Com ([198.6.49.176]) by smtp-ima.symantec.com
with SMTP
(IMA Internet Exchange 3.0 Enterprise) id 0013810D; Wed, 15 Jul 98 14:39:27
-0700
Received: from lserver.symantec.com (lserver.symantec.com [198.6.49.6])
by mailer.Symantec.Com (8.8.8/8.8.8) with ESMTP id OAA13293
for <CAllen@symantec.com>; Wed, 15 Jul 1998 14:41:33 -0700 (PDT)
Received: from mercury.Sun.COM (mercury.Sun.COM [192.9.25.1]) by
lserver.symantec.com (8.8.4/8.7.6) with SMTP id NAA23782 for
<CAllen@symantec.com>; Wed, 15 Jul 1998 13:37:28 -0700 (PDT)
Received: from Eng.Sun.COM (engmail3 [129.144.170.5]) by mercury.Sun.COM
(SMI-8.6/mail.byaddr) with SMTP id NAA00277 for <CAllen@symantec.com>; Wed, 15
Jul 1998 13:36:59 -0700
Received: from shorter.eng.sun.com (shorter.Eng.Sun.COM [129.144.252.35])
by Eng.Sun.COM (SMI-8.6/SMI-5.3) with SMTP id NAA07642;
Wed, 15 Jul 1998 13:36:55 -0700
Received: from laguna.eng.sun.com by shorter.eng.sun.com (SMI-8.6/SMI-SVR4)
id NAA13937; Wed, 15 Jul 1998 13:36:55 -0700
Received: from laguna by laguna.eng.sun.com (SMI-8.6/SMI-SVR4)
id NAA28056; Wed, 15 Jul 1998 13:36:52 -0700
Date: Wed, 15 Jul 1998 13:36:52 -0700 (PDT)
From: Jan Luehe <Jan.Luehe@Eng.Sun.COM>
Reply-To: Jan Luehe <Jan.Luehe@Eng.Sun.COM>
Subject: Re: Re[2]: Trying to write a Provider
To: java-security@java.Sun.COM, Jan.Luehe@Eng.Sun.COM, CAllen@symantec.com
Message-ID: <libSDtMail.9807151336.22669.luehe@shorter>
MIME-Version: 1.0
Content-Type: TEXT/plain; charset=us-ascii
Content-MD5: MXXEkVdwQVEWp0AT5rrlKg==
X-Mailer: dtmail 1.1.0 CDE Version 1.1 SunOS 5.5.1 sun4u sparc
--IMA.Boundary.7167260090--