This commit is contained in:
Looly 2021-09-09 11:53:11 +08:00
parent 57c191fe1c
commit 5be6c0103b
4 changed files with 52 additions and 2 deletions

View File

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

View File

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

View File

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

View File

@ -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." +