io.quarkiverse.langchain4j.deployment.HashUtil Maven / Gradle / Ivy
The newest version!
package io.quarkiverse.langchain4j.deployment;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class HashUtil {
public static String sha1(String value) {
return sha1(value.getBytes(StandardCharsets.UTF_8));
}
public static String sha1(byte[] value) {
try {
MessageDigest md = MessageDigest.getInstance("SHA-1");
byte[] digest = md.digest(value);
StringBuilder sb = new StringBuilder(40);
for (int i = 0; i < digest.length; ++i) {
sb.append(Integer.toHexString((digest[i] & 0xFF) | 0x100).substring(1, 3));
}
return sb.toString();
} catch (NoSuchAlgorithmException e) {
throw new IllegalStateException(e);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy