JDK 1.8 版本以上(含)
class Md5Pass{
private static String ss="ISMvKXpXpadDiUoOSoAfww==";
public static void main(String[] args) throws UnsupportedEncodingException, NoSuchAlgorithmException {
System.out.println(login("admin"));
}
public static boolean login(String pass) throws UnsupportedEncodingException, NoSuchAlgorithmException {
if(md52(pass).equals(ss)){
System.out.println(md52("123"));
return true;
}
else{
return false;
}
}
public static String md52(String pass) {
MessageDigest md= null;
try {
md = MessageDigest.getInstance("md5");
//通过Md5 计算摘要
byte[] b= new byte[0];
b = md.digest(pass.getBytes("UTF-8"));
String str= Base64.getEncoder().encodeToString(b);
return str;
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
}
JDK 1.8 以下
没有访问权限 要添加
Base64Encoder bas=new Base64Encoder();
bas.encode(b);
Base64Encoder deco=new Base64Encoder();
bytes =deco.decodeBuffer();