class ArrayUtils {

    public static byte[] toByteArray(BigInteger value, int expectedBytesLength) {
        byte[] input = value.toByteArray();
        int byteTmpLength = input.length;

        if (byteTmpLength <= expectedBytesLength) {
            return input;
        }

        int copyStartIndex = 0;
        byte[] result;

        if (input[0] == 0x00) {
            copyStartIndex = 1;
        }

        result = new byte[expectedBytesLength];

        System.arraycopy(input, copyStartIndex, result, 0, expectedBytesLength);

        return result;
    }

}