public static byte[] toBigEndianBytes(BigInteger n) {
    if (n.signum() == -1) {
      throw new IllegalArgumentException("n must not be negative");
    }
    return n.toByteArray();
  }
Encodes a non-negative {@link java.math.BigInteger} into the minimal two's-complement
representation in big-endian byte-order.

<p>The most significant bit of the first byte is the sign bit, which is always 0 because the
input number is non-negative. Because of that, the output is at the same time also an unsigned
big-endian encoding that may have an additional zero byte at the beginning, and can be parsed
with {@link #fromUnsignedBigEndianBytes}.
java_src/src/main/java/com/google/crypto/tink/internal/BigIntegerEncoding.java