91名师指路-头部
91名师指路

ShaUtils 工具类

由于某些原因,现在不支持支付宝支付,如需要购买源码请加博主微信进行购买,微信号:13248254750

package com.mszl.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.security.MessageDigest;

/**
* SHA256加密工具类
*/
public class ShaUtils {

private static final Logger logger = LoggerFactory.getLogger(ShaUtils.class);

public static String encodeSHA256(String testString) {
byte[] data = testString.getBytes();
try {
MessageDigest md = MessageDigest.getInstance("SHA-256");
byte[] digest = md.digest(data);
return bytes2Hex(digest);
} catch (Exception e) {
logger.warn("加密失败", e);
return "";
}
}

private static String bytes2Hex(byte[] bts) {
StringBuilder sb = new StringBuilder();
String tmp;
for (byte bt : bts) {
tmp = (Integer.toHexString(bt & 0xFF));
if (tmp.length() == 1) {
sb.append("0");
}
sb.append(tmp);
}
return sb.toString().toUpperCase();
}

}


2019-08-23 14:22:32     阅读(1634)

名师出品,必属精品    https://www.91mszl.com

联系博主    
用户登录遮罩层
x

账号登录

91名师指路-底部