1. 程式人生 > >SpringBoot 密碼MD5加密

SpringBoot 密碼MD5加密

row encoder bytes string exception code exce utf-8 digest

public class PasswordEncrypt {

    public static String encodeByMd5(String string) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        // 確定計算方法
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        Base64.Encoder base64Encoder = Base64.getEncoder();
        // 加密字符串
        return base64Encoder.encodeToString(md5.digest(string.getBytes("utf-8")));
    }
}

SpringBoot 密碼MD5加密