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 // Password = String "mozq123"; 13 is String password = "liubei123" ; 14 // String S = DigestUtils.md5DigestAsHex (password.getBytes ()); 15 16 // carried salt . 17 // String Salt = "mozq"; 18 is 19 // generates a random salt value 20 is // String = RandomStringUtils.random salt (10); 21 is // String = RandomStringUtils.randomAlphabetic salt (10); 22 is String RandomStringUtils.randomAlphabetic salt = (. 5,. 8 ); 23 is the System.out .println (Salt); 24 System.out.println (salt.length ()); 25 26 is String passwordSalt = + Salt password; 27 // Get MD5 encryption tools, encryption 28 // String S = DigestUtils.md5DigestAsHex (passwordSalt.getBytes ()); 29 30 31 is / * 32 encryption solutions given Spring 33 is * / 34 is BCryptPasswordEncoder Encoder = new new BCryptPasswordEncoder (); 35 String S = encoder.encode (password); 36 // $ RcVrPsuSd3BPiBWdXF.ncO96Ls99VSIY92zZ0.z7F6jFPmjsRzaOC. 2A $ 10 $ 37 [ //$2a$10$M.fk6zjeH/7By7Krcem0u.wWsdSiorJ2do98QLZJjssUWwx2eCfeW 38 System.out.println(s); 39 System.out.println(s.length()); 40 } 41 }
User Role permission to query the user to add encryption bcrypt bug collection salted MD5 password encryption of random salt spring
Guess you like
Origin www.cnblogs.com/mozq/p/11071773.html
Ranking