public static String stringToMD5(String str) {

        StringBuffer buffer = new StringBuffer();
        MessageDigest messagedigest = null;

        if (StringUtil.isNullOrEmpty(str))
            return "";

        try {
            messagedigest = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            logger.error(e);
            return "";
        }

        byte[] b = messagedigest.digest(str.getBytes());
        for (int i = 0; i < b.length; i++)
            buffer.append(byteToHexString(b[i]));

        return buffer.toString();
    }