mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-05-04 12:47:55 +08:00
完善 SaSecureUtil 单元测试
This commit is contained in:
parent
c7ce21fde7
commit
a1b563b85b
@ -33,6 +33,9 @@ import cn.dev33.satoken.exception.SaTokenException;
|
||||
*/
|
||||
public class SaSecureUtil {
|
||||
|
||||
private SaSecureUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Base64编码
|
||||
*/
|
||||
|
@ -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权限认证框架");
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user