public static String encode(byte[] input) {
      if (input.length == 0) {
         return "";
      }
      input = copyOfRange(input, 0, input.length);
      // Count leading zeroes.
      int zeroCount = 0;
      while (zeroCount < input.length && input[zeroCount] == 0) {
         ++zeroCount;
      }
      // The actual encoding.
      byte[] temp = new byte[input.length * 2];
      int j = temp.length;

      int startAt = zeroCount;
      while (startAt < input.length) {
         byte mod = divmod58(input, startAt);
         if (input[startAt] == 0) {
            ++startAt;
         }
         temp[--j] = (byte) ALPHABET[mod];
      }

      // Strip extra '1' if there are some after decoding.
      while (j < temp.length && temp[j] == ALPHABET[0]) {
         ++j;
      }
      // Add as many leading '1' as there were leading zeros.
      while (--zeroCount >= 0) {
         temp[--j] = (byte) ALPHABET[0];
      }

      byte[] output = copyOfRange(temp, j, temp.length);
      try {
         return new String(output, "US-ASCII");
      } catch (UnsupportedEncodingException e) {
         throw new RuntimeException(e); // Cannot happen.
      }
   }
public static String encode ( byte [ ] input ) { if ( input . length == 0 ) { return "" ; } input = copyOfRange ( input , 0 , input . length ) ; int zeroCount = 0 ; while ( zeroCount < input . length && input [ zeroCount ] == 0 ) { ++ zeroCount ; } byte [ ] temp = new byte [ input . length * 2 ] ; int j = temp . length ; int startAt = zeroCount ; while ( startAt < input . length ) { byte mod = divmod58 ( input , startAt ) ; if ( input [ startAt ] == 0 ) { ++ startAt ; } temp [ -- j ] = ( byte ) ALPHABET [ mod ] ; } while ( j < temp . length && temp [ j ] == ALPHABET [ 0 ] ) { ++ j ; } while ( -- zeroCount >= 0 ) { temp [ -- j ] = ( byte ) ALPHABET [ 0 ] ; } byte [ ] output = copyOfRange ( temp , j , temp . length ) ; try { return new String ( output , "US-ASCII" ) ; } catch ( UnsupportedEncodingException e ) { throw new RuntimeException ( e ) ; } }
Encodes the given bytes in base58. No checksum is appended.

@param input byte array input
@return string encoded in Base58