All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.h3xstream.retirejs.util.HashUtil Maven / Gradle / Ivy

There is a newer version: 3.0.4
Show newest version
package com.h3xstream.retirejs.util;

import java.security.DigestException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class HashUtil {

    public static String hashSha1(byte[] content, int offset) {
        try {
            MessageDigest digest = MessageDigest.getInstance("SHA-1");
            digest.update(content, offset, content.length - offset);
            return toHex(digest.digest());
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e); //Will never happen, unless executed on a martian JVM.
        }
    }

    private static String toHex(byte[] value) {
        StringBuilder sb = new StringBuilder();
        for (byte b : value) {
            sb.append(String.format("%02x", b));
        }
        return sb.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy