I'm working on an integration with a partner that uses Java's BigInteger to generate a byte array as the key for a simple encryption algorithm. I'm trying to find the equivalent .NET code without much luck.
The Java code they're using is:
String keyString = "48B734DA47388C656913C9BF5146E186";
byte key[] = new BigInteger(keyString, 16).toByteArray();
which yields the following byte array:
[72, -73, 52, -38, 71, 56, -116, 101, 105, 19, -55, -65, 81, 70, -31, -122]
This alone is troubling because bytes in .NET range from 0-255 so the negative values are out of range.
The closest .NET code I came up with is:
string keyString = "48B734DA47388C656913C9BF5146E186";
byte[] key = BigInteger.Parse(keyString, NumberStyles.HexNumber).ToByteArray();
which yields the following byte array:
[134, 225, 70, 81, 191, 201, 19, 105, 101, 140, 56, 71, 218, 52, 183, 72]
At this point, I'm thinking a .NET equivalent simply isn't possible - especially because of the negative byte values.
I look forward to everyone's thoughts.
.Cast<sbyte>().ToArray();afterToByteArray(). Should work.which yields the following byte array- That is not a byte array. In any case, it is aSystem.SByte[].bytearray which are signed values. The second is .Netbytearray which are not signed values.var s = String.Join(",", key.Reverse().Select(x => (sbyte)x).ToArray());sbyteinstead ofbyte?