- import java.security.MessageDigest;
- import java.security.NoSuchAlgorithmException;
- import org.apache.commons.codec.binary.Hex;
- public class MD5Util {
- private static MessageDigest md = null;
- static{
- try {
- md = MessageDigest.getInstance("MD5");
- } catch (NoSuchAlgorithmException e) {
- e.printStackTrace();
- }
- }
- /**
- * 获取MD5签名
- * @param content
- * @return
- */
- public static String getMD5Sign(String content){
- if(md == null || content == null || content.equals("")) return null;
- md.reset();
- return new String(Hex.encodeHex(md.digest(content.getBytes())));
- }
- }