package com.wanggjie.weishi.utils;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* @author 王杰
* @time 2017/2/13 20:57
* @desc MD5加密
*/
public class MD5Utils {
public static void testMd5(String text) {
//获得一个MD5的数字摘要器
MessageDigest md5 = null;
try {
md5 = MessageDigest.getInstance("md5");
} catch (NoSuchAlgorithmException e) {
//自定义一个字符串
String str = text;
StringBuilder sb = new StringBuilder();
byte[] bytes = md5.digest(str.getBytes());
for (byte byt : bytes) {
String pass = Integer.toHexString(byt & 0xff);
//md5加密时不允许出现1位数的解析
if (pass.length() == 1) {
sb.append("1");
}
sb.append(pass);
}
e.printStackTrace();
}
}
}
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* @author 王杰
* @time 2017/2/13 20:57
* @desc MD5加密
*/
public class MD5Utils {
public static void testMd5(String text) {
//获得一个MD5的数字摘要器
MessageDigest md5 = null;
try {
md5 = MessageDigest.getInstance("md5");
} catch (NoSuchAlgorithmException e) {
//自定义一个字符串
String str = text;
StringBuilder sb = new StringBuilder();
byte[] bytes = md5.digest(str.getBytes());
for (byte byt : bytes) {
String pass = Integer.toHexString(byt & 0xff);
//md5加密时不允许出现1位数的解析
if (pass.length() == 1) {
sb.append("1");
}
sb.append(pass);
}
e.printStackTrace();
}
}
}