Java生成MD5加密字符串

import java.security.MessageDigest;

public class MD5Utils {

    public static String getMD5String(String s){
        StringBuffer result = new StringBuffer();
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(s.getBytes());
            for (byte tmp: md5.digest()
                 ) {
                result.append(String.format("%02X", tmp));
            }
        }catch (Exception e){

        }
        return result.toString();
    }
}

你可能感兴趣的:(Java)