Hello I am new here and have a problem concerning cryptography-provider.
Following coding runs perfectly well on SUNs JRE and not on the IBM implementation. Since we use PowerPCs on another Site we have to use the IBM version:
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.Signature;
class RSATest {
private static final byte[] testString = { 0x01, 0x02, 0x03, 0x04, 0x05,
0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03,
0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
0x07, 0x08 };
public static void main(String[] args) throws NoSuchAlgorithmException {
/* Test generating and verifying a DSA signature */
try {
/* generate a key pair */
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
keyGen.initialize(1024, new SecureRandom());
KeyPair pair = keyGen.generateKeyPair();
MessageDigest md = MessageDigest.getInstance("SHA-1");
md.update(testString);
PrivateKey priv = pair.getPrivate();
byte[] digest = md.digest();
Signature rsaSign = Signature.getInstance("RawRSA");
Signature rsaVerify = Signature.getInstance("RawRSA");
rsaSign.initSign(priv);
rsaSign.update(digest);
byte[] sig = rsaSign.sign();
PublicKey pub = pair.getPublic();
rsaVerify.initVerify(pub);
rsaVerify.update(digest);
boolean verifies = rsaVerify.verify(sig);
if (verifies)
System.out.println("Verifies with our implementation");
else
System.out.println("Failed our verify. (WRONG!)");
rsaVerify = Signature.getInstance("RawRSA");
digest[0]++;
rsaVerify.initVerify(pub);
rsaVerify.update(digest);
verifies = rsaVerify.verify(sig);
if (verifies)
System.out.println("Bad signature verifies (WRONG!)");
else
System.out.println("Bad signature doesn't verify (OK)");
} catch (Exception e) {
System.err.println("Caught exception " + e.toString());
e.printStackTrace(System.out);
}
}
}
the java.security File contains the following entries for SUN:
security.provider.1=cryptix.provider.Cryptix
security.provider.2=COM.claymoresystems.provider.ClaymoreProvider
For IBM its:
security.provider.1=cryptix.provider.Cryptix
security.provider.2=COM.claymoresystems.provider.ClaymoreProvider
security.provider.3=com.ibm.crypto.provider.IBMJCE
the third one is needed to let the KeyPair be generated properly in the IBM Version. No clue why...
zitpcx6053 ~ $ ~/tmp/ibm-java-i386-60/jre/bin/java -jar test.jar
Caught exception java.security.SignatureException: RawRSAPKCS#1: Not initialized
java.security.SignatureException: RawRSAPKCS#1: Not initialized
at COM.claymoresystems.provider.RSASignature.engineUpdate(RSASignature.java:152)
at java.security.Signature$SignatureImpl.engineUpdate(Signature.java:469)
at java.security.Signature.update(Signature.java:325)
at RSATest.main(RSATest.java:36)
zitpcx6053 ~ $ java -jar test.jar
Verifies with our implementation
Bad signature doesn't verify (OK)
zitpcx6053 ~ $
The used provider-libraries are:
puretls.jar
cryptix32.jar
cryptix-asn1.jar
I did my testing on a Linux machine (SL5), but similar Problem occurs on the PowerPC.
If annyone can help -- please do so :)
Regards,
Jan