```
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class Test01 {
//MD5加密程序
public String getMD5String(String str) {
//获取用户输入的某个字符串来进行加密运算,采用java自带的方式来进行加密
try {
//生成加密摘要
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.update(str.getBytes());
return new BigInteger(1, md5.digest()).toString(16);
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
public boolean judgeMD5(String user,String pass) {
String userMD5 = getMD5String(user);
String passMD5 = getMD5String(pass);
//与数据库查询出的数据进行对比
if(userMD5.equals("22cbd383bb473ee567d51ca2ce4cc677")&&passMD5.equals("21232f297a57a5a743894a0e4a801fc3"))
return true;
else
return false;
}
}
```