question: public static byte [ ] toUnsignedByteArray ( BigInteger bi ) { if ( bi == null ) { return null ; } byte [ ] bb = bi . toByteArray ( ) ; if ( bb [ 0 ] == 0 ) { byte [ ] noZero = new byte [ bb . length - 1 ] ; System . arraycopy ( bb , 1 , noZero , 0 , noZero . length ) ; return noZero ; } else { return bb ; } }
target:  Remove first byte if 0. Needed because BigInteger.toByteArray() sometimes returns a zero prefix.