New file |
| | |
| | | package com.cl.util; |
| | | |
| | | import org.apache.commons.codec.digest.DigestUtils; |
| | | import org.mindrot.jbcrypt.BCrypt; |
| | | |
| | | public class BCryptPasswordEncoder { |
| | | |
| | | // 加密密码(自动生成盐值) |
| | | public static String encode(String rawPassword) { |
| | | return BCrypt.hashpw(rawPassword, BCrypt.gensalt()); |
| | | } |
| | | |
| | | // 验证密码 |
| | | public static boolean matches(String rawPassword, String encodedPassword) { |
| | | return BCrypt.checkpw(rawPassword, encodedPassword); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(); |
| | | System.out.println(encoder.encode("123456")); |
| | | System.out.println(DigestUtils.md5Hex("111111")); |
| | | } |
| | | } |