/** * Generate a SHA 512 checksum from the data in the given buffer and asynchronously return the hex encoded hash as a string. * * @param buffer * @return Observable returning the SHA 512 checksum */ public static Single<String> hash(Buffer buffer) { return hash(Flowable.just(buffer)); }
/** * Generate a SHA 512 checksum from the given file and asynchronously return the hex encoded hash as a string. * * @param path */ public static String hash(String path) { try { MessageDigest md = MessageDigest.getInstance("SHA-512"); try (InputStream is = Files.newInputStream(Paths.get(path)); DigestInputStream mis = new DigestInputStream(is, md)) { byte[] buffer = new byte[4096]; while (mis.read(buffer) >= 0) { } } byte[] digest = md.digest(); return bytesToHex(digest); } catch (Exception e) { log.error("Error while hashing file {" + path + "}", e); throw error(INTERNAL_SERVER_ERROR, "node_error_upload_failed", e); } }