- 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())));
- }
- }
本文转自william_xu 51CTO博客,原文链接:http://blog.51cto.com/williamx/1088889,如需转载请自行联系原作者