Here you can find the source of toBytes(BigInteger bigInt, int expectedSize)
public static byte[] toBytes(BigInteger bigInt, int expectedSize)
//package com.java2s; //License from project: BSD License import java.math.BigInteger; public class Main { public static byte[] toBytes(BigInteger bigInt, int expectedSize) { byte[] tempArray = bigInt.toByteArray(); byte[] resArray = new byte[expectedSize]; if (tempArray.length > expectedSize) { System.arraycopy(tempArray, (tempArray.length - expectedSize), resArray, 0, expectedSize); return resArray; } else {//from ww w . ja va 2s . c om return tempArray; } } }