fix crypto

This commit is contained in:
Looly
2019-08-30 21:39:42 +08:00
parent f124fd0681
commit e777fbf5ce
8 changed files with 107 additions and 12 deletions

View File

@@ -5,6 +5,7 @@ import java.security.KeyPair;
import org.junit.Assert;
import org.junit.Test;
import cn.hutool.core.lang.Console;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.HexUtil;
import cn.hutool.core.util.StrUtil;
@@ -59,6 +60,8 @@ public class RSATest {
// 公钥加密,私钥解密
byte[] encrypt = rsa.encrypt(StrUtil.bytes("我是一段测试aaaa", CharsetUtil.CHARSET_UTF_8), KeyType.PublicKey);
Console.log(HexUtil.encodeHexStr(encrypt));
byte[] decrypt = rsa.decrypt(encrypt, KeyType.PrivateKey);
Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt, CharsetUtil.CHARSET_UTF_8));

View File

@@ -30,7 +30,7 @@ public class SymmetricTest {
// 随机生成密钥
byte[] key = KeyUtil.generateKey(SymmetricAlgorithm.AES.getValue()).getEncoded();
// 构建
SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, key);