Posted on 2007-01-26 14:18
小傻 阅读(281)
评论(0) 编辑 收藏 所属分类:
jsp
package test;
import java.util.*;
import java.io.*;
import java.security.MessageDigest;
public class PWD {
public String encryptPWD(String sPassword) {
byte cResult[] = new byte[16];
String sResult = "";
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update( ("litianyi" + sPassword).getBytes());
cResult = md.digest();
for (int i = 0; i < cResult.length; i++) {
if (cResult[i] < 0)
cResult[i] += 128;
String sTemp = Integer.toHexString(cResult[i]).toUpperCase();
if (cResult[i] < 16)
sTemp = "0" + sTemp;
sResult += sTemp;
}
}
catch (Exception e) {
sResult = "";
}
return sResult;
}
}
Test_MD5.jsp
<%@ page contentType="text/html;charset=gb2312" import="test.PWD"%>
<%
String a="123456";
PWD n=new PWD();
out.println(n.encryptPWD(a));
%>