io.lsn.spring.utilities.hash.Hash Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of utilities Show documentation
Show all versions of utilities Show documentation
Logisfera Nova Commons holds a bunch of useful helpers such as validators, conditional register
process, soap logging handler
package io.lsn.spring.utilities.hash;
import io.lsn.logger.factory.LoggerFactory;
import io.lsn.logger.factory.logger.Logger;
import io.lsn.logger.factory.LoggerFactory;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class Hash {
private static final Logger logger = LoggerFactory.getLogger(Hash.class);
public static String md5(String input) {
return hash(input, "MD5");
}
public static String sha256(String input) {
return hash(input, "SHA-256");
}
private static String hash(String input, String algorithm) {
MessageDigest digest = null;
if (null == input) {
return null;
}
try {
digest = MessageDigest.getInstance(algorithm);
digest.update(input.getBytes(), 0, input.length());
} catch (NoSuchAlgorithmException e) {
logger.error(e.getMessage(), e);
}
assert digest != null;
return new BigInteger(1, digest.digest()).toString(16);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy