Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Security / January 2004

Tip: Looking for answers? Try searching our database.

Verfication doesn't work

Thread view: 
Peter Zenz - 04 Jan 2004 11:06 GMT
Hello,
I have written a small program for signing byte-arrays with DSA. The
provider is Cryptix. Unfortunately my program doesn't work correct. The
verification says, that the signature is not correct. Can anybody help me? I
don't know how to find the bug.

Peter

import java.security.*;

class Sign
{
//Signature dsa;

 public static void main(String[] dxfds)
 {
 byte[] signature=null;

 byte[] input="This text will be signed with DSA".getBytes();
 int keysize=512;
 //Keygeneration
 KeyPair myKeys=null;
 java.security.Security.addProvider(new cryptix.provider.Cryptix());
 KeyPairGenerator keyGen;

 try{
  //random = java.security.SecureRandom.getInstance("RSA","Cryptix");
  keyGen = KeyPairGenerator.getInstance("DSA");
  keyGen.initialize(keysize);
  myKeys=keyGen.generateKeyPair();
  }
  catch(NoSuchAlgorithmException n){System.out.println("Der Algorithmus ist
unbekannt");}
 //Generation of the signature
 Signature dsa=null;
 try
 {
  dsa=Signature.getInstance("DSA");
  dsa.initSign(myKeys.getPrivate());
 }
 //catch(NoSuchProviderException n){System.out.println("Provider ist
unbekannt!");}
 catch(NoSuchAlgorithmException n){System.out.println("Algorithm doesn't
exist!");}
 catch(InvalidKeyException n){System.out.println("Imnvalid Key");}
 try{
  dsa.update(input);
 }
 catch(SignatureException n){}

 try
 {
  signature=dsa.sign();
  for(int i=0; i<signature.length;i++ )
  System.out.println(signature[i]);
 }
 catch(SignatureException n){}

// boolean ok;

 // Verifikation:
 Signature dsaver=null;
   try
   {
    dsaver=Signature.getInstance("DSA");
    dsaver.initVerify(myKeys.getPublic());
   }
   //catch(NoSuchProviderException n){System.out.println("Provider ist
unbekannt!");}
   catch(NoSuchAlgorithmException n){System.out.println("Algo does't
exist!");}
   catch(InvalidKeyException n){System.out.println("Key is invalid");}

 try{
  //System.out.println("Catch-Block!");

  boolean ok=dsaver.verify(signature);
  //System.out.println("DEr Wert ist "+ok);
  //System.out.println("test1");
  if(ok)
  {System.out.println("Verfication is o.k.");}
  // System.out.println("test2");}
  else
  {System.out.println("Verfication is not o.k.");}
 }
 catch(SignatureException n){System.out.println("Exception");}

}

}
nobody - 04 Jan 2004 15:44 GMT
> Hello,
> I have written a small program for signing byte-arrays with DSA. The
[quoted text clipped - 71 lines]
>   try{
>    //System.out.println("Catch-Block!");

You have to do:

    dsaver.update(input);

before verifying.  i.e., sequence of steps is:

Signature dsaver = Signature.getInstance("DSA");

dsaver.initSign(keys.getPrivate());
dsaver.update(input);
byte[] sig = dsaver.sign();

// sig now holds signature

dsaver.initVerify(keys.getPublic());
dsaver.update(input);
boolean ok = dsaver.verify(sig);

>    boolean ok=dsaver.verify(signature);
>    //System.out.println("DEr Wert ist "+ok);
[quoted text clipped - 10 lines]
>
> }


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.