public static byte[] doubleDigest(byte[] input) { return doubleDigest(input, 0, input.length); }
/** * Uses the checksum in the last 4 bytes of the decoded data to verify the rest * are correct. The checksum is removed from the returned data. * * @throws Exception * if the input is not base 58 or the checksum does not validate. */ public static byte[] decodeChecked(String input) throws Exception { byte[] tmp = decode(input); if (tmp.length < 4) throw new Exception("Input too short"); byte[] checksum = new byte[4]; System.arraycopy(tmp, tmp.length - 4, checksum, 0, 4); byte[] bytes = new byte[tmp.length - 4]; System.arraycopy(tmp, 0, bytes, 0, tmp.length - 4); tmp = doubleDigest(bytes); byte[] hash = new byte[4]; System.arraycopy(tmp, 0, hash, 0, 4); if (!Arrays.equals(hash, checksum)) throw new Exception("Checksum does not validate"); return bytes; }