Java Digital Signature - Signing same text twice

paulrofl332

New Member
I've been using the Java security api and was following the tutorial on how to generate digital signatures: http://docs.oracle.com/javase/tutorial/security/apisign/gensig.htmlI've used the code but instead of parsing a file, I've parsed in a string: "hello" and got it signed. I then print out the byte array produced using \[code\]new String()\[/code\]. This is all well and good but when I sign the same string with the same key, I get a different signature. Here is the code I've used:\[code\]Signature dsa = Signature.getInstance("SHA1withDSA", "SUN");dsa.initSign(priv);String message = "hello";byte[] buffer = new byte[1024];buffer = message.getBytes();int len;dsa.update(buffer);byte[] realSig = dsa.sign();byte[] buffer2 = new byte[1024];buffer2 = message.getBytes();dsa.update(buffer2); byte[] realSig2 = dsa.sign();System.out.println(new String(realSig2));\[/code\]I was expecting an identical signature both times as the messages and private keys do not change. Any advice would be much appreciated.
 
Top