Recently I was working on torrent encryption protocol, which uses Diffie-Hellman key exchange. I used .net built-in System.Numerics assembly which offers the BigInteger structure. Event ModPow method was included. “Great, there is event ToByteArray method”, I thought. Then I spent two days of debugging because I didn’t check the byte order returned by this method. Why does Microsoft always implement things this way? As a developer I would expect to have the following signature of the BigInteger structure:
public struct BigInteger : // some interfaces
{
public BigInteger(byte[] value);
public BigInteger(byte[] value, ByteOrder endianness);
public byte[] ToByteArray();
public byte[] ToByteArray(ByteOrder endianness);
// other members
}