chen.lin
2 天以前 9140aee230de0ef41de9682a9353fbd372e2bcaa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.vincent.rsf.server.common.security;
 
import org.junit.jupiter.api.Test;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 
/**
 * 字符串加密与验证。
 *
 */
class SecurityDemoControllerTest {
 
    @Test
    void encryptAndVerify() {
        BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
        String raw = "wms001";
 
        // 加密
        String encoded = encoder.encode(raw);
        System.out.println("密文: " + encoded);
 
        // 验证:原文与加密结果匹配
        boolean ok = encoder.matches(raw, encoded);
        System.out.println("加密后验证: " + ok);
 
        // 验证:错误原文不匹配
        boolean bad = encoder.matches("wrong", encoded);
        System.out.println("错误原文验证: " + bad);
    }
}