标签:pack stat cat 加密工具 ack [] mes main util
package com.google;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* @author CQY13 MD5加密工具类
*/
public class MD5Utils {
/**
* 获取MD5加密
*
* @param pwd
* 需要加密的字符串
* @return String字符串 加密后的字符串
*/
public static String getPwd(String pwd) {
try {
MessageDigest digest = MessageDigest.getInstance("md5");
byte[] bs = digest.digest(pwd.getBytes());
String hexString = "";
for (byte b : bs) {
int temp = b & 255;
if (temp < 16 && temp >= 0) {
// 手动补上一个“0”
hexString = hexString + "0" + Integer.toHexString(temp);
} else {
hexString = hexString + Integer.toHexString(temp);
}
}
return hexString;
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}
/**
* @param args
*/
public static void main(String[] args) {
String pwd = MD5Utils.getPwd("admin!@#$..");
System.out.println(pwd);
}
}
标签:pack stat cat 加密工具 ack [] mes main util
原文地址:http://www.cnblogs.com/CAOXIAOYANG/p/7883905.html