package com.vci.ubcs.starter.web.util;
|
|
//
|
// Source code recreated from a .class file by IntelliJ IDEA
|
// (powered by FernFlower decompiler)
|
//
|
|
|
import java.security.MessageDigest;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
|
public class Md5 {
|
private static Logger logger = LoggerFactory.getLogger(Md5.class);
|
|
public Md5() {
|
}
|
|
public static String md5(String v) {
|
if (v == null) {
|
return null;
|
} else {
|
try {
|
MessageDigest md = MessageDigest.getInstance("MD5");
|
return toHex(md.digest(v.getBytes()));
|
} catch (Exception var2) {
|
return null;
|
}
|
}
|
}
|
|
public static String twoTimesMd5(String sourceString) throws Exception {
|
return sourceString == null ? null : md5(md5(sourceString));
|
}
|
|
public static boolean equalMd5(String md5String, String sourceString) {
|
if (md5String != null && sourceString != null) {
|
try {
|
return md5String.equals(twoTimesMd5(sourceString));
|
} catch (Exception var3) {
|
var3.printStackTrace();
|
return false;
|
}
|
} else {
|
return false;
|
}
|
}
|
|
public static boolean equalOneMd5(String md5String, String sourceString) {
|
if (md5String != null && sourceString != null) {
|
try {
|
String ms = md5(sourceString);
|
return md5String.equals(ms);
|
} catch (Exception var3) {
|
if (logger.isErrorEnabled()) {
|
logger.error("对比md5的时候出现了错误", var3);
|
}
|
|
return false;
|
}
|
} else {
|
return false;
|
}
|
}
|
|
private static String toHex(byte[] buffer) {
|
StringBuffer sb = new StringBuffer(32);
|
String s = null;
|
|
for(int i = 0; i < buffer.length; ++i) {
|
s = Integer.toHexString(buffer[i] & 255);
|
if (s.length() < 2) {
|
sb.append('0');
|
}
|
|
sb.append(s);
|
}
|
|
return sb.toString();
|
}
|
}
|