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);
|
}
|
}
|