As pointed out in the comments, the reason you're seeing different values between the byte[] from the C# BigInteger and the Java BigInteger is that the byte order is reversed: C# is little-endian and Java is big-endian.
(See Java vs. C#: BigInteger hex string yields different result? for more details).
As you can see, the order of the bytes in the array is exactly reversed:
C#
BigInteger bi = BigInteger.Parse("1379080579050447841330186236235223160927998000398161138225875482305250883605652677639242794753995315199229112894647269426499088162253680340518114657361569012095908691691924534414360438924914998");
byte[] ba = bi.ToByteArray();
for (int i = 0; i < ba.Length; i++) {
Console.Write(ba[i] + " ");
}
// 54 49 48 50 47 52 48 47 49 50 32 111 110 114 111 105 103 32 44 98 117 108 67
// 32 97 116 105 118 69 32 44 101 108 97 117 113 115 97 80 32 101 110 111 105 108
// 103 101 86 32 111 116 110 101 118 69 32 44 52 57 57 49 47 56 48 47 49 50 32 44
// 105 115 115 111 82 32 111 99 114 97 77
Java
BigInteger bi = new BigInteger("1379080579050447841330186236235223160927998000398161138225875482305250883605652677639242794753995315199229112894647269426499088162253680340518114657361569012095908691691924534414360438924914998");
byte[] ba = bi.toByteArray();
for (int i = 0; i < ba.length; i++) {
System.out.print(ba[i] + " ");
}
// 77 97 114 99 111 32 82 111 115 115 105 44 32 50 49 47 48 56 47 49 57 57 52 44
// 32 69 118 101 110 116 111 32 86 101 103 108 105 111 110 101 32 80 97 115 113 117
// 97 108 101 44 32 69 118 105 116 97 32 67 108 117 98 44 32 103 105 111 114 110 111
// 32 50 49 47 48 52 47 50 48 49 54
If you want a Java byte[] to hold the bytes in the same order as C#, you will need to reverse its contents.
You can just write a simple helper method that reverses the order of the bytes in the array:
public static void reverse(byte[] array) {
for (int i = 0, j = array.length - 1; i < j; i++, j--) {
byte b = array[i];
array[i] = array[j];
array[j] = b;
}
}
Or if you have access to 3rd-party libraries, you can use org.apache.commons.lang3.ArrayUtils.reverse(byte[]).
That would give you a byte[] in Java holding the bytes in the same order as C#:
Java
BigInteger bi = new BigInteger("1379080579050447841330186236235223160927998000398161138225875482305250883605652677639242794753995315199229112894647269426499088162253680340518114657361569012095908691691924534414360438924914998");
byte[] ba = bi.toByteArray();
reverse(ba);
for (int i = 0; i < ba.length; i++) {
System.out.print(ba[i] + " ");
}
// 54 49 48 50 47 52 48 47 49 50 32 111 110 114 111 105 103 32 44 98 117 108 67
// 32 97 116 105 118 69 32 44 101 108 97 117 113 115 97 80 32 101 110 111 105 108
// 103 101 86 32 111 116 110 101 118 69 32 44 52 57 57 49 47 56 48 47 49 50 32 44
// 105 115 115 111 82 32 111 99 114 97 77
Byte[]ever. I suggest using abyte[].