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;
  }
}

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 ; } }
remove first byte if 0 . needed because biginteger . tobytearray ( ) sometimes returns a zero prefix .
