com.yixan.tools.common.util.CryptoUtil Maven / Gradle / Ivy
package com.yixan.tools.common.util;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 加密解密工具类
*
* @author zhaohuihua
* @version V1.0 2016年3月1日
*/
public abstract class CryptoUtil {
private static final Logger log = LoggerFactory.getLogger(CryptoUtil.class);
public static String md5(String text) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
return HexUtil.toString(md.digest(text.getBytes()));
} catch (NoSuchAlgorithmException e) {
log.error("MD5 error", e);
return null;
}
}
public static String sha256(String text) {
try {
MessageDigest md = MessageDigest.getInstance("SHA-256");
return HexUtil.toString(md.digest(text.getBytes()));
} catch (NoSuchAlgorithmException e) {
log.error("SHA-256 error", e);
return null;
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy