/**
*
* @param inStr 加密字符串
* @param type 加密方式 sha sha-256
* @return
*/
public static String sha(String inStr,String type) {
MessageDigest sha = null;
byte[] byteArray = null;
try {
sha = MessageDigest.getInstance(type);
byteArray = inStr.getBytes("UTF-8");
} catch (Exception e) {
System.out.println(e.toString());
e.printStackTrace();
return "";
}
byte[] md5Bytes = sha.digest(byteArray);
StringBuffer hexValue = new StringBuffer();
for (int i = 0; i < md5Bytes.length; i++) {
int val = ((int) md5Bytes[i]) & 0xff;
if (val < 16) {
hexValue.append("0");
}
hexValue.append(Integer.toHexString(val));
}
return hexValue.toString().toLowerCase();
}
Java实现sha1和sha256加密
最新推荐文章于 2024-08-25 02:09:50 发布