public static byte[] toByteArray(final BigInteger value,final int numBytes){
  final byte[] outputBytes=new byte[numBytes];
  final byte[] bigIntegerBytes=value.toByteArray();
  int copyStartIndex=(0x00 == bigIntegerBytes[0]) ? 1 : 0;
  int numBytesToCopy=bigIntegerBytes.length - copyStartIndex;
  if (numBytesToCopy > numBytes) {
    copyStartIndex+=numBytesToCopy - numBytes;
    numBytesToCopy=numBytes;
  }
  for (int i=0; i < numBytesToCopy; ++i) {
    outputBytes[i]=bigIntegerBytes[copyStartIndex + numBytesToCopy - i - 1];
  }
  return outputBytes;
}

public static byte [ ] toByteArray ( final BigInteger value , final int numBytes ) { final byte [ ] outputBytes = new byte [ numBytes ] ; final byte [ ] bigIntegerBytes = value . toByteArray ( ) ; int copyStartIndex = ( 0x00 == bigIntegerBytes [ 0 ] ) ? 1 : 0 ; int numBytesToCopy = bigIntegerBytes . length - copyStartIndex ; if ( numBytesToCopy > numBytes ) { copyStartIndex += numBytesToCopy - numBytes ; numBytesToCopy = numBytes ; } for ( int i = 0 ; i < numBytesToCopy ; ++ i ) { outputBytes [ i ] = bigIntegerBytes [ copyStartIndex + numBytesToCopy - i - 1 ] ; } return outputBytes ; }
converts a biginteger to a little endian byte array .
