question: static byte [ ] toByteArray ( BigInteger bi ) { byte [ ] b = bi . toByteArray ( ) ; if ( ( b . length > 1 ) && ( b [ 0 ] == 0 ) ) { int n = b . length - 1 ; byte [ ] newarray = new byte [ n ] ; System . arraycopy ( b , 1 , newarray , 0 , n ) ; b = newarray ; } return b ; }
target:  Utility method to convert a BigInteger to a byte array in unsigned format as needed in the handshake messages. BigInteger uses 2's complement format, i.e. it prepends an extra zero if the MSB is set. We remove that.