mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
add test
This commit is contained in:
parent
57c191fe1c
commit
5be6c0103b
@ -1,5 +1,6 @@
|
||||
package cn.hutool.core.exceptions;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@ -34,4 +35,15 @@ public class ExceptionUtilTest {
|
||||
IOException ioException1 = ExceptionUtil.convertFromOrSuppressedThrowable(argumentException, IOException.class, true);
|
||||
Assert.assertNotNull(ioException1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bytesIntConvertTest(){
|
||||
final String s = Convert.toStr(12);
|
||||
final int integer = Convert.toInt(s);
|
||||
Assert.assertEquals(12, integer);
|
||||
|
||||
final byte[] bytes = Convert.intToBytes(12);
|
||||
final int i = Convert.bytesToInt(bytes);
|
||||
Assert.assertEquals(12, i);
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ public class ChaCha20Test {
|
||||
byte[] iv = RandomUtil.randomBytes(12);
|
||||
|
||||
final SymmetricCrypto chacha = new SymmetricCrypto("ChaCha20",
|
||||
KeyUtil.generateKey("ChaCha", key),
|
||||
KeyUtil.generateKey("ChaCha20", key),
|
||||
new IvParameterSpec(iv)
|
||||
);
|
||||
|
||||
|
@ -0,0 +1,38 @@
|
||||
package cn.hutool.crypto.test.symmetric;
|
||||
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.crypto.KeyUtil;
|
||||
import cn.hutool.crypto.symmetric.SymmetricCrypto;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
|
||||
public class ZucTest {
|
||||
|
||||
@Test
|
||||
public void zuc128Test(){
|
||||
final SecretKey secretKey = KeyUtil.generateKey("zuc-128");
|
||||
byte[] iv = RandomUtil.randomBytes(16);
|
||||
final SymmetricCrypto zuc = new SymmetricCrypto("zuc-128", secretKey, new IvParameterSpec(iv));
|
||||
|
||||
String msg = RandomUtil.randomString(500);
|
||||
byte[] crypt2 = zuc.encrypt(msg);
|
||||
String msg2 = zuc.decryptStr(crypt2, CharsetUtil.CHARSET_UTF_8);
|
||||
Assert.assertEquals(msg, msg2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void zuc256Test(){
|
||||
final SecretKey secretKey = KeyUtil.generateKey("zuc-256");
|
||||
byte[] iv = RandomUtil.randomBytes(25);
|
||||
final SymmetricCrypto zuc = new SymmetricCrypto("zuc-256", secretKey, new IvParameterSpec(iv));
|
||||
|
||||
String msg = RandomUtil.randomString(500);
|
||||
byte[] crypt2 = zuc.encrypt(msg);
|
||||
String msg2 = zuc.decryptStr(crypt2, CharsetUtil.CHARSET_UTF_8);
|
||||
Assert.assertEquals(msg, msg2);
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ public class JWTTest {
|
||||
.setPayload("sub", "1234567890")
|
||||
.setPayload("name", "looly")
|
||||
.setPayload("admin", true)
|
||||
.setPayload(RegisteredPayload.EXPIRES_AT, DateUtil.parse("2022-01-01"))
|
||||
.setExpiresAt(DateUtil.parse("2022-01-01"))
|
||||
.setKey(key);
|
||||
|
||||
String rightToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9." +
|
||||
|
Loading…
x
Reference in New Issue
Block a user