package com.auto.lyric.util;
|
|
import java.security.MessageDigest;
|
import java.security.NoSuchAlgorithmException;
|
|
/**
|
* Created by Runt (qingingrunt2010@qq.com) on 2022/5/29.
|
*/
|
public class SHA1UTIL {
|
|
public static String getSHA(String info) {
|
byte[] bytesSHA = null;
|
try {
|
|
MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
|
|
messageDigest.update(info.getBytes());
|
|
bytesSHA = messageDigest.digest();
|
} catch (NoSuchAlgorithmException e) {
|
e.printStackTrace();
|
}
|
String strSHA = byteToHex(bytesSHA);
|
return strSHA;
|
}
|
|
|
private static String byteToHex(byte[] bytes) {
|
String hs = "";
|
String temp;
|
for (byte b : bytes) {
|
temp = (Integer.toHexString(b & 0XFF));
|
if (temp.length() == 1) {
|
hs = hs + "0" + temp;
|
} else {
|
hs = hs + temp;
|
}
|
}
|
return hs;
|
}
|
|
/**
|
* MD5加密之方法二
|
* @explain java实现
|
* @param str
|
* 待加密字符串
|
* @return 16进制加密字符串
|
*/
|
public static String MD5(String str) {
|
// 加密后的16进制字符串
|
String hexStr = "";
|
try {
|
// 此 MessageDigest 类为应用程序提供信息摘要算法的功能
|
MessageDigest md5 = MessageDigest.getInstance("MD5");
|
// 转换为MD5码
|
byte[] digest = md5.digest(str.getBytes("utf-8"));
|
hexStr = byteToHex(digest);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return hexStr;
|
}
|
|
}
|