package com.base.utils.tools.java;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * MD5加密32位小写
 */

public class MD5Util {

    /**
     * 加密成32位MD5
     * @param sSecret 用于加密的目标字符
     */
    public static String getMd5Value32(String sSecret) {
        try {
            MessageDigest bmd5 = MessageDigest.getInstance("MD5");
            bmd5.update(sSecret.getBytes());
            int i;
            StringBuffer buf = new StringBuffer();
            byte[] b = bmd5.digest();
            for (int offset = 0; offset < b.length; offset++) {
                i = b[offset];
                if (i < 0)
                    i += 256;
                if (i < 16)
                    buf.append("0");
                buf.append(Integer.toHexString(i));
            }
            return buf.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }

}
