add method

This commit is contained in:
Looly
2020-11-17 23:41:14 +08:00
parent 9ca25e26d6
commit 11e6a28113
8 changed files with 89 additions and 17 deletions

View File

@@ -1,13 +1,12 @@
package cn.hutool.crypto.test.asymmetric;
import cn.hutool.core.map.MapUtil;
import org.junit.Assert;
import org.junit.Test;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.asymmetric.Sign;
import cn.hutool.crypto.asymmetric.SignAlgorithm;
import org.junit.Assert;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;

View File

@@ -2,12 +2,17 @@ package cn.hutool.crypto.test.symmetric;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.util.HexUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.crypto.KeyUtil;
import cn.hutool.crypto.Mode;
import cn.hutool.crypto.Padding;
import cn.hutool.crypto.symmetric.AES;
import org.junit.Assert;
import org.junit.Test;
import javax.crypto.SecretKey;
import java.security.SecureRandom;
public class AESTest {
@Test
@@ -95,4 +100,17 @@ public class AESTest {
Assert.assertEquals("16c5", aes.decryptStr(Base64.decode("ecIQ0+MEkyz56mqciHxtfA==")));
// ------------------------------------------------------------------------
}
@Test
public void aesWithSha1PrngTest() {
final SecureRandom random = RandomUtil.getSecureRandom("123456".getBytes());
final SecretKey secretKey = KeyUtil.generateKey("AES", 128, random);
String content = "12sdfsdfs你好啊";
AES aes = new AES(secretKey);
final String result1 = aes.encryptBase64(content);
final String decryptStr = aes.decryptStr(result1);
Assert.assertEquals(content, decryptStr);
}
}