完善 SaSecureUtil 单元测试

This commit is contained in:
click33 2022-09-02 23:38:29 +08:00
parent c7ce21fde7
commit a1b563b85b
3 changed files with 25 additions and 1 deletions

View File

@ -33,6 +33,9 @@ import cn.dev33.satoken.exception.SaTokenException;
*/
public class SaSecureUtil {
private SaSecureUtil() {
}
/**
* Base64编码
*/

View File

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

View File

@ -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权限认证框架");
}
}