1 パッケージcn.itcast.encode。 2 3 インポートorg.apache.commons.lang3.RandomStringUtils。 4 インポートorg.springframework.security.crypto.bcrypt.BCryptPasswordEncoder。 5 輸入org.springframework.util.DigestUtils。 6 7 インポートjava.io.UnsupportedEncodingException。 8 9 パブリック クラスMD5Demo { 10 公共 静的 ボイドメイン(文字列[]引数)がスローにUnsupportedEncodingException { 11 // 文字列のパスワード= "liu123を"; 12 // パスワード=文字列"mozq123"; 13である 文字列のパスワード= "liubei123" ; 14 // 文字列s = DigestUtils.md5DigestAsHex(password.getBytes()); 15 16 // 実施塩 。17 // 文字列ソルト= "mozq"; 18であります 19 // ランダムなソルト値生成 20である // 文字列= RandomStringUtils.random塩(10); 21である // 文字列= RandomStringUtils.randomAlphabetic塩(10); 22である (図5 ,. 8文字列RandomStringUtils.randomAlphabetic塩= ); 23である のSystem.out .println(塩); 24 System.out.println(salt.length()); 25 26は、ある 文字列passwordSalt = +塩のパスワード; 27 // 取得したMD5暗号化ツール、暗号化 28 // 文字列S = DigestUtils.md5DigestAsHex(passwordSalt.getBytes()); 29 30 31は、 / * 32の 春所与の暗号化ソリューション である33 * / 34である = BCryptPasswordEncoderエンコーダ新しい新; BCryptPasswordEncoder() 35 文字列S = encoder.encode(パスワード); 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 }
バグのコレクションはランダムなソルトスプリングのMD5のパスワード暗号化を塩漬けbcryptの暗号化を追加するようにユーザーを照会するユーザの役割権限
おすすめ
転載: www.cnblogs.com/mozq/p/11071773.html
ランキング