Base58Utils { public static byte[] decodeWithCheck(final String encoded) throws IOException { if (null == encoded || encoded.length() == 0) { return new byte[0]; } final byte[] rawTotal = decode(encoded); final byte[] rawData = Arrays.copyOfRange(rawTotal, 0, rawTotal.length - CHECKSUM_LEN); final byte[] checkSum = Arrays.copyOfRange(rawTotal, rawTotal.length - CHECKSUM_LEN, rawTotal.length); final byte[] calculatedCheckSum = calculateCheckSum(rawData); if (!Arrays.equals(checkSum, calculatedCheckSum)) { logger.info("Checksum is mismatch - Input: {}, Computed: {}", checkSum, calculatedCheckSum); throw new IllegalArgumentException("Checksum is mismatch"); } return rawData; }  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 testDecodeWithCheck() throws IOException { assertTrue( Arrays.equals(DECODED_WITH_CHECKSUM, Base58Utils.decodeWithCheck(ENCODED_WITH_CHECKSUM))); assertTrue(Arrays.equals(new byte[0], Base58Utils.decodeWithCheck(""))); assertTrue(Arrays.equals(new byte[0], Base58Utils.decodeWithCheck(null))); }