Suns java into J# DSA Problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • toxxi

    #1

    Suns java into J# DSA Problem

    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
    {
    KeyPairGenerato r keypairgenerato r =
    KeyPairGenerato r.getInstance(" DSA");
    SecureRandom sec = new SecureRandom(s) ;

    keypairgenerato r.initialize(51 2, sec);
    a = keypairgenerato r.generateKeyPa ir().getPrivate ();
    }
    catch (NoSuchAlgorith mException nosuchalgorithm exception)
    {
    System.err.prin tln(nosuchalgor ithmexception);
    }

    try
    {
    Signature signature = Signature.getIn stance("DSA");
    signature.initS ign(a);
    signature.updat e(key);
    byte1 = signature.sign( );
    }
    catch (Exception exception)
    {
    System.err.prin tln(exception);
    }

    System.out.prin tln(byte1.lengt h ); // suns java ~46 byte long, MS J#
    only 40 bytes :-(

    for (int i = 0; i < byte1.length; i++)
    {
    System.out.prin t((int)byte1[i] + " ");
    }
    }
    }


Working...