If I use this little Prg under Sun's Java, the outputbytearray (byte1) is ~46
bytes long! If I use it under J# the outputbytearray (byte 1) is all the time
only 40 bytes long! Can anyone show me how to correct this problem? I can't
use the "generated" key anymore under J#, because the bytelenght differs
from the one in java. Or maybe anyone can traslate it into c#?
Here is the source :
import java.security.*;
public class Untitled1
{
public static PrivateKey a;
public static void main(String[] args)
{
byte key[] = { 1,2,3,4,5,6,7,8 };
byte s[] = { 19, 120, 108, 92, 115, 33, -119,-38, -97, -77, -49, 27, 6,
78, -90, 105, -102, 87, -110, -90 };
byte byte1[] = new byte[0];
try
{
KeyPairGenerator keypairgenerator =
KeyPairGenerator.getInstance("DSA");
SecureRandom sec = new SecureRandom(s);
keypairgenerator.initialize(512, sec);
a = keypairgenerator.generateKeyPair().getPrivate();
}
catch (NoSuchAlgorithmException nosuchalgorithmexception)
{
System.err.println(nosuchalgorithmexception);
}
try
{
Signature signature = Signature.getInstance("DSA");
signature.initSign(a);
signature.update(key);
byte1 = signature.sign();
}
catch (Exception exception)
{
System.err.println(exception);
}
System.out.println(byte1.length ); // suns java ~46 byte long, MS J#
only 40 bytes :-(
for (int i = 0; i < byte1.length; i++)
{
System.out.print((int)byte1[i] + " ");
}
}
}