public class Test {
public boolean checkPW(String userId, String orgPassword, String secPassword) {
String md5 = getMD5String(userId + orgPassword);
return md5.equals(secPassword);
}
private String getMD5String(String str) {
try {
MessageDigest md5 = MessageDigest.getInstance("md5");
byte[] b = str.getBytes();
byte[] digest = md5.digest(b);
char[] chars = new char[]{'0', '1', '2', '3', '4', '5',
'6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
StringBuffer sb = new StringBuffer();
for (byte bb : digest) {
sb.append(chars[(bb >> 4) & 15]);
sb.append(chars[bb & 15]);
}
return sb.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return null;
}
public static void main(String[] args) {
Test test = new Test();
System.out.println(test.getMD5String("001123456"));
System.out.println(test.checkPW("001", "123456", "D2E94DD634AB69D6BCEA03200A663EC1"));
}
}
评论