package com.yihu.jw.healthCare.utils;

import java.security.MessageDigest;

public class MD5 {
    public MD5() {
    }

    public static String md5(String str) {
        return md5(str, "utf-8");
    }

    public static String md5(String str, String charset) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(str.getBytes(charset));
            byte[] b = md.digest();
            StringBuffer buf = new StringBuffer("");

            for(int offset = 0; offset < b.length; ++offset) {
                int i = b[offset];
                if (i < 0) {
                    i += 256;
                }

                if (i < 16) {
                    buf.append("0");
                }

                buf.append(Integer.toHexString(i));
            }

            str = buf.toString();
        } catch (Exception var7) {
            var7.printStackTrace();
        }

        return str;
    }

    public static void main(String[] args) {
        System.out.println(md5("appid=test&appsecret=test1234&data={\"aid\":\"2\",\"bid\":\"1\"}&funid=ybjjtest&key=testkey").toUpperCase());
    }
}