import javasecuritymessagedigest;
import javasecuritynosuchalgorithmexception;
/**
* md5工具类
*
* @author
* @version 0
*/
public class md5util {
/**
* md
*
* @param value the value
* @return the string
*/
public static string md5(string value) {
try {
messagedigest md = messagedigestgetinstance("md5");
byte[] e = mddigest(valuegetbytes());
return tohex(e);
}
catch (nosuchalgorithmexception e) {
eprintstacktrace();
return value;
}
}
/**
* md
*
* @param bytes the bytes
* @return the string
*/
public static string md5(byte[] bytes){
try {
messagedigest md = messagedigestgetinstance("md5");
byte[] e = mddigest(bytes);
return tohex(e);
}
catch (nosuchalgorithmexception e) {
e.printstacktrace();
return "";
}
}
/**
* to hex
*
* @param bytes the bytes
* @return the string
*/
private static string tohex(byte bytes[]){
stringbuilder hs = new stringbuilder();
string stmp ="";
for (int n = 0; n < byteslength; n++) {
stmp = integertohexstring(bytes[n] & 0xff);
if (stmplength() == 1)
hsappend("0")append(stmp);
else
hsappend(stmp);
}
return hstostring();
}
}
如对本文有疑问,
点击进行留言回复!!
相关文章:
-
-
-
-
-
Java基础篇一
选一个自己喜欢的开发工具我这里先选择IDEA进行讲解,如需要下载MyEclipse的话我可以提供下载地址,或者直...
[阅读全文]
-
常用的配置文件
web.xml最新版Servlet的配置文件:web.xml<?xml version="1.0" enc...
[阅读全文]
-
-
-
-
-
网友评论