mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-12-20 03:49:45 +08:00
完善 SaSecureUtil 单元测试
This commit is contained in:
@@ -33,6 +33,9 @@ import cn.dev33.satoken.exception.SaTokenException;
|
|||||||
*/
|
*/
|
||||||
public class SaSecureUtil {
|
public class SaSecureUtil {
|
||||||
|
|
||||||
|
private SaSecureUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base64编码
|
* Base64编码
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import cn.dev33.satoken.secure.BCrypt;
|
|||||||
public class BCryptTest {
|
public class BCryptTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void checkpwTest() {
|
public void testCheckpw() {
|
||||||
final String hashed = BCrypt.hashpw("12345");
|
final String hashed = BCrypt.hashpw("12345");
|
||||||
// System.out.println(hashed);
|
// System.out.println(hashed);
|
||||||
Assertions.assertTrue(BCrypt.checkpw("12345", hashed));
|
Assertions.assertTrue(BCrypt.checkpw("12345", hashed));
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package cn.dev33.satoken.core.secure;
|
package cn.dev33.satoken.core.secure;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@@ -63,4 +65,23 @@ public class SaSecureUtilTest {
|
|||||||
Assertions.assertEquals(text2, "Sa-Token 一个轻量级java权限认证框架");
|
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