cn.minsin.yiketong.util.SignUtil Maven / Gradle / Ivy
package cn.minsin.yiketong.util;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class SignUtil {
/**
* MD5
* @param data
* @return
*/
public static String encode(String data) {
StringBuffer buf = new StringBuffer("");
try {
MessageDigest md = MessageDigest.getInstance("MD5");
try {
md.update(data.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
byte b[] = md.digest();
int i;
for (int offset = 0; offset < b.length; offset++) {
i = b[offset];
if (i < 0)
i += 256;
if (i < 16)
buf.append("0");
buf.append(Integer.toHexString(i));
}
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return buf.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy