• 用户角色权限查询添加bug集锦 用户密码加密 MD5 加盐 随机盐 spring的加密bcrypt


     1 package cn.itcast.encode;
     2 
     3 import org.apache.commons.lang3.RandomStringUtils;
     4 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
     5 import org.springframework.util.DigestUtils;
     6 
     7 import java.io.UnsupportedEncodingException;
     8 
     9 public class MD5Demo {
    10     public static void main(String[] args) throws UnsupportedEncodingException {
    11 //        String password = "liu123";
    12 //        String password = "mozq123";
    13         String password = "liubei123";
    14 //        String s = DigestUtils.md5DigestAsHex(password.getBytes());
    15 
    16         //进行加盐
    17 //        String salt = "mozq";
    18 
    19         //生成随机盐值
    20 //        String salt = RandomStringUtils.random(10);
    21 //        String salt = RandomStringUtils.randomAlphabetic(10);
    22         String salt = RandomStringUtils.randomAlphabetic(5, 8);
    23         System.out.println(salt);
    24         System.out.println(salt.length());
    25 
    26         String passwordSalt = salt + password;
    27         //获取MD5加密工具,进行加密
    28 //        String s = DigestUtils.md5DigestAsHex(passwordSalt.getBytes());
    29 
    30 
    31         /*
    32             Spring给出的加密解决方案
    33          */
    34         BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
    35             String s = encoder.encode(password);
    36         //$2a$10$RcVrPsuSd3BPiBWdXF.ncO96Ls99VSIY92zZ0.z7F6jFPmjsRzaOC
    37         //$2a$10$M.fk6zjeH/7By7Krcem0u.wWsdSiorJ2do98QLZJjssUWwx2eCfeW
    38         System.out.println(s);
    39         System.out.println(s.length());
    40     }
    41 }
    Spring加密工具BCryptPasswordEncoder

  • 相关阅读:
    python字符串的第一个字符和最后字符
    python str和repr的区别
    python list tuple知识点
    python list append 相关知识点
    python dict remove,删除
    python windows和linux下安装和配置
    python 集合的相关操作
    python list 合并连接字符串
    python中文视频教程
    小程序授权登录
  • 原文地址:https://www.cnblogs.com/mozq/p/11071773.html
Copyright © 2020-2023  润新知