mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-09-18 17:48:03 +08:00
完善 SaSecureUtil 单元测试
This commit is contained in:
@@ -14,7 +14,7 @@ import cn.dev33.satoken.secure.BCrypt;
|
||||
public class BCryptTest {
|
||||
|
||||
@Test
|
||||
public void checkpwTest() {
|
||||
public void testCheckpw() {
|
||||
final String hashed = BCrypt.hashpw("12345");
|
||||
// System.out.println(hashed);
|
||||
Assertions.assertTrue(BCrypt.checkpw("12345", hashed));
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package cn.dev33.satoken.core.secure;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -63,4 +65,23 @@ public class SaSecureUtilTest {
|
||||
Assertions.assertEquals(text2, "Sa-Token 一个轻量级java权限认证框架");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rsaEncryptByPrivate() throws Exception {
|
||||
|
||||
// 生成私钥和公钥
|
||||
HashMap<String, String> map = SaSecureUtil.rsaGenerateKeyPair();
|
||||
String privateKey = map.get("private");
|
||||
String publicKey = map.get("public");
|
||||
|
||||
// 文本
|
||||
String text = "Sa-Token 一个轻量级java权限认证框架";
|
||||
|
||||
// 使用公钥加密
|
||||
String ciphertext = SaSecureUtil.rsaEncryptByPrivate(privateKey, text);
|
||||
|
||||
// 使用私钥解密
|
||||
String text2 = SaSecureUtil.rsaDecryptByPublic(publicKey, ciphertext);
|
||||
Assertions.assertEquals(text2, "Sa-Token 一个轻量级java权限认证框架");
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user