public static byte[] asUnsignedByteArray(int length,BigInteger value){
  byte[] bytes=value.toByteArray();
  if (bytes[0] == 0) {
    if (bytes.length - 1 > length) {
      throw new IllegalArgumentException("standard length exceeded for value");
    }
    byte[] tmp=new byte[length];
    System.arraycopy(bytes,1,tmp,tmp.length - (bytes.length - 1),bytes.length - 1);
    return tmp;
  }
 else {
    if (bytes.length == length) {
      return bytes;
    }
    if (bytes.length > length) {
      throw new IllegalArgumentException("standard length exceeded for value");
    }
    byte[] tmp=new byte[length];
    System.arraycopy(bytes,0,tmp,tmp.length - bytes.length,bytes.length);
    return tmp;
  }
}

public static byte [ ] asUnsignedByteArray ( int length , BigInteger value ) { byte [ ] bytes = value . toByteArray ( ) ; if ( bytes [ 0 ] == 0 ) { if ( bytes . length - 1 > length ) { throw new IllegalArgumentException ( "standard length exceeded for value" ) ; } byte [ ] tmp = new byte [ length ] ; System . arraycopy ( bytes , 1 , tmp , tmp . length - ( bytes . length - 1 ) , bytes . length - 1 ) ; return tmp ; } else { if ( bytes . length == length ) { return bytes ; } if ( bytes . length > length ) { throw new IllegalArgumentException ( "standard length exceeded for value" ) ; } byte [ ] tmp = new byte [ length ] ; System . arraycopy ( bytes , 0 , tmp , tmp . length - bytes . length , bytes . length ) ; return tmp ; } }
return the passed in value as an unsigned byte array .
