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

}