mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
30 lines
759 B
Java
30 lines
759 B
Java
package com.commafeed.backend;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
import com.google.common.hash.HashFunction;
|
|
import com.google.common.hash.Hashing;
|
|
|
|
import lombok.experimental.UtilityClass;
|
|
|
|
@UtilityClass
|
|
@SuppressWarnings("deprecation")
|
|
public class Digests {
|
|
|
|
public static String sha1Hex(byte[] input) {
|
|
return hashBytesToHex(Hashing.sha1(), input);
|
|
}
|
|
|
|
public static String sha1Hex(String input) {
|
|
return hashBytesToHex(Hashing.sha1(), input.getBytes(StandardCharsets.UTF_8));
|
|
}
|
|
|
|
public static String md5Hex(String input) {
|
|
return hashBytesToHex(Hashing.md5(), input.getBytes(StandardCharsets.UTF_8));
|
|
}
|
|
|
|
private static String hashBytesToHex(HashFunction function, byte[] input) {
|
|
return function.hashBytes(input).toString();
|
|
}
|
|
}
|