# Problem with DSA sign/verify

Sangeeta Varma (Sangeeta.Varma@Eng)
Fri, 10 Jul 1998 14:08:30 -0700 (PDT)

- Messages sorted by: [ date ][ thread ][ subject ][ author ]
- Next message: Jan Luehe: "Re: Problem with DSA sign/verify"
- Previous message: 18960.@java.sun.com: "NEVADA CORPS QUICK AND CHEAP!!!!"
- Next in thread: Jan Luehe: "Re: Problem with DSA sign/verify"

    Message-Id: <199807102110.OAA27411@basilisk.Eng.Sun.COM>

    Date: Fri, 10 Jul 1998 14:08:30 -0700 (PDT)

    From: Sangeeta Varma <Sangeeta.Varma@Eng>

    Subject: Problem with DSA sign/verify

    To: java-security@java.Sun.COM

--Array_of_Hedgehogs_130_000
Content-Type: TEXT/plain; charset=us-ascii
Content-MD5: bGgDLnEcjC9ISaRBobYvUQ==

Hi,

I have a very simple program which makes use of the javasoft's provider for
DSA key gen and signature. I generate a pair of keys, and then use the
private key to sign a piece of data, and want to verify it using the public key
generated. The program is always unable to verify the data. I do the same steps
with an RSA provider that I have written, and this test program works fine.

Is there a problem with the DSA sign/verify or am I missing something here ?

Thanks!
Sangeeta

--Array_of_Hedgehogs_130_000
Content-Type: TEXT/plain; name="test.java"; charset=us-ascii; x-unix-mode=0644
Content-Description: test.java
Content-MD5: W194gBUfsyeuj8fsP0YQIA==

/*
* Copyright (c) 1998, by Sun Microsystems, Inc.
* All rights reserved.
*
*/

import java.security.*;
import java.io.IOException;
import java.io.PrintStream;
import java.io.FileOutputStream;
import java.math.BigInteger;

/** Test driver program for DSA Signature **/
public class test {

public void test() {

}

public KeyPair genKeys() {

KeyPairGenerator kpg = null;

// Load the provider which implements DSA generation.
try {
kpg = KeyPairGenerator.getInstance("DSA");

} catch (Exception e) {
System.out.println("Driver:: " + e.getMessage());
return null;
}

dbgln("FOUND PROVIDER : " + kpg);
dbgln("Driver: initializing now.. ");

// Pass the parameters for key generation

try {
kpg.initialize(512, new SecureRandom());
} catch (Exception e) {
System.out.println("Driver:Exception : " + e.getMessage() );
return null;
}

dbgln("Driver: generating key pair .. ");

// Generate the Key Pair
KeyPair keypair = kpg.generateKeyPair();

dbgln("Driver : PRIVATEKEY : " + keypair.getPrivate());
dbgln("Driver : PUBLICKEY : " + keypair.getPublic());

return keypair;
}

public static void main(String args[]) {

/* Are we debugging ?? */
String debugOpt = System.getProperty("debug", "false");

if (debugOpt.compareTo("true") == 0)
_debug = true;
else
_debug = false;

byte[] inputNum = (new BigInteger("123456")).toByteArray();
test drv = new test();
KeyPair keys = drv.genKeys();
Signature signObj = null;
byte[] signature = null;

try {
signObj = Signature.getInstance("SHA-1/DSA");

} catch (Exception e) {
System.out.println(e.getMessage());
return;
}

try {
signObj.initSign(keys.getPrivate());
} catch (InvalidKeyException e) {
System.out.println(e.toString());
return;
}

dbgln("Updating data now!!");
try {
signObj.update(inputNum, 0, inputNum.length);
dbgln("signing data now!!");
signature = signObj.sign();
} catch (SignatureException e) {
System.out.println(e.toString());
return;
}

dbgln("Signature Len = " + signature.length);

try {
signObj.initVerify(keys.getPublic());
} catch (InvalidKeyException e) {
System.out.println(e.toString());
return;
}

try {
if (signObj.verify(signature))
System.out.println("Verification successful!!");
else
System.out.println("Verification failed!!");
} catch (SignatureException e) {
System.out.println(e.toString());
return;
}
}

public static void dbgln(String msg) {
if (_debug)
System.out.println(msg);
}

private static boolean _debug = false;
}

--Array_of_Hedgehogs_130_000--

- Next message: Jan Luehe: "Re: Problem with DSA sign/verify"
- Previous message: 18960.@java.sun.com: "NEVADA CORPS QUICK AND CHEAP!!!!"
- Next in thread: Jan Luehe: "Re: Problem with DSA sign/verify"