public byte[] sign() { //byte[] sig=signature.sign(); cs.Close(); System.Security.Cryptography.DSACryptoServiceProvider DSA = new System.Security.Cryptography.DSACryptoServiceProvider(); DSA.ImportParameters(DSAKeyInfo); System.Security.Cryptography.DSASignatureFormatter DSAFormatter = new System.Security.Cryptography.DSASignatureFormatter(DSA); DSAFormatter.SetHashAlgorithm("SHA1"); byte[] sig =DSAFormatter.CreateSignature( sha1 ); return sig; }
public byte[] sign() { //byte[] sig=signature.sign(); cs.Close(); System.Security.Cryptography.DSACryptoServiceProvider DSA = new System.Security.Cryptography.DSACryptoServiceProvider(); DSA.ImportParameters(DSAKeyInfo); System.Security.Cryptography.DSASignatureFormatter DSAFormatter = new System.Security.Cryptography.DSASignatureFormatter(DSA); DSAFormatter.SetHashAlgorithm("SHA1"); byte[] sig = DSAFormatter.CreateSignature(sha1); return(sig); }
//This method will probably won't work, we need to get rid of the ASN.1 format (Tamir) public byte[] sign() { //byte[] sig=signature.sign(); cs.Close(); System.Security.Cryptography.DSACryptoServiceProvider DSA = new System.Security.Cryptography.DSACryptoServiceProvider(); DSA.ImportParameters(DSAKeyInfo); System.Security.Cryptography.DSASignatureFormatter DSAFormatter = new System.Security.Cryptography.DSASignatureFormatter(DSA); DSAFormatter.SetHashAlgorithm("SHA1"); byte[] sig =DSAFormatter.CreateSignature( sha1 ); /* System.out.print("sign["+sig.length+"] "); for(int i=0; i<sig.length;i++){ System.out.print(Integer.toHexString(sig[i]&0xff)+":"); } System.out.println(""); */ // sig is in ASN.1 // SEQUENCE::={ r INTEGER, s INTEGER } int len=0; int index=3; len=sig[index++]&0xff; //System.out.println("! len="+len); byte[] r=new byte[len]; Array.Copy(sig, index, r, 0, r.Length); index=index+len+1; len=sig[index++]&0xff; //System.out.println("!! len="+len); byte[] s=new byte[len]; Array.Copy(sig, index, s, 0, s.Length); byte[] result=new byte[40]; // result must be 40 bytes, but length of r and s may not be 20 bytes Array.Copy(r, (r.Length>20)?1:0, result, (r.Length>20)?0:20-r.Length, (r.Length>20)?20:r.Length); Array.Copy(s, (s.Length>20)?1:0, result, (s.Length>20)?20:40-s.Length, (s.Length>20)?20:s.Length); // System.arraycopy(sig, (sig[3]==20?4:5), result, 0, 20); // System.arraycopy(sig, sig.length-20, result, 20, 20); return result; }