33
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package cn.shangyu.gdxzExpert.utils;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
|
||||
public class MD5Utils {
|
||||
private static String YAN = "sadw44dwddwd4w4ef4r5442366edf";
|
||||
public static String md5Encrypt(String str){
|
||||
try {
|
||||
MessageDigest digest = MessageDigest.getInstance("md5");
|
||||
byte[] bys = digest.digest((str+YAN).getBytes());
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for(byte bb : bys){
|
||||
int num = bb & 0xff;
|
||||
String hex = Integer.toHexString(num);
|
||||
if(hex.length() == 1){
|
||||
sb.append("0");
|
||||
}
|
||||
sb.append(hex);
|
||||
}
|
||||
return sb.toString();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* md5Hex
|
||||
* 使用Apache digest做md5加密
|
||||
* @param str
|
||||
* @return
|
||||
* String
|
||||
*/
|
||||
public static String md5Hex(String str){
|
||||
return DigestUtils.md5Hex(str);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user