对称密码增加update功能

This commit is contained in:
飘辰
2021-06-09 16:13:30 +08:00
parent 68f73c9e64
commit b3a191bf90
2 changed files with 42 additions and 0 deletions

View File

@@ -14,6 +14,7 @@ import cn.hutool.crypto.symmetric.DESede;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;
import cn.hutool.crypto.symmetric.Vigenere;
import java.nio.charset.StandardCharsets;
import org.junit.Assert;
import org.junit.Test;
@@ -108,6 +109,19 @@ public class SymmetricTest {
Assert.assertEquals("cd0e3a249eaf0ed80c330338508898c4bddcfd665a1b414622164a273ca5daf7b4ebd2c00aaa66b84dd0a237708dac8e", encryptHex);
}
@Test
public void aesUpdateTest() {
String content = "4321c9a2db2e6b08987c3b903d8d11ff";
AES aes = new AES(Mode.CBC, Padding.PKCS5Padding, "0123456789ABHAEQ".getBytes(), "DYgjCEIMVrj2W9xN".getBytes());
// 加密为16进制表示
String randomData = aes.updateHex(content.getBytes(StandardCharsets.UTF_8));
String randomData2 = aes.updateHex(content.getBytes(StandardCharsets.UTF_8));
Assert.assertEquals(randomData2, randomData);
Assert.assertEquals(randomData, "cd0e3a249eaf0ed80c330338508898c4");
}
@Test
public void aesZeroPaddingTest() {
String content = RandomUtil.randomString(RandomUtil.randomInt(200));