By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,656 Members | 1,027 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,656 IT Pros & Developers. It's quick & easy.

Suns java into J# DSA Problem

P: n/a
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] + " ");
}
}
}
Nov 22 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.