Base58Utils { public static String encode(final byte[] input) { if (null == input || input.length == 0) { return ""; } final char[] encoded = new char[input.length * 2]; final byte[] copy = Arrays.copyOf(input, input.length); int zeros = 0; while (zeros < input.length && input[zeros] == 0) { ++zeros; } int inputIndex = zeros; int outputIndex = encoded.length; while (inputIndex < copy.length) { encoded[--outputIndex] = BASE58_CHARS[divmod(copy, inputIndex, 256, 58)]; if (copy[inputIndex] == 0) { ++inputIndex; } } while (outputIndex < encoded.length && encoded[outputIndex] == ENCODED_ZERO) { ++outputIndex; } while (--zeros >= 0) { encoded[--outputIndex] = ENCODED_ZERO; } return new String(encoded, outputIndex, encoded.length - outputIndex); }  static String encode(final byte[] input); static byte[] decode(final String input); static String encodeWithCheck(final byte[] rawData); static byte[] decodeWithCheck(final String encoded);  }
@Test public void testEncode() { assertEquals(ENCODED, Base58Utils.encode(DECODED)); assertEquals("", Base58Utils.encode(new byte[0])); assertEquals("", Base58Utils.encode(null)); }