add XXTEA

This commit is contained in:
Looly
2022-03-05 23:49:27 +08:00
parent 899f1384f6
commit 580e2e9fbe
3 changed files with 176 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
package cn.hutool.crypto.test.symmetric;
import cn.hutool.crypto.symmetric.SymmetricCrypto;
import cn.hutool.crypto.symmetric.XXTEA;
import org.junit.Assert;
import org.junit.Test;
@@ -10,7 +11,7 @@ import org.junit.Test;
public class TEATest {
@Test
public void teaTest(){
public void teaTest() {
String data = "测试的加密数据 by Hutool";
// 密钥必须为128bit
@@ -24,7 +25,7 @@ public class TEATest {
}
@Test
public void xteaTest(){
public void xteaTest() {
String data = "测试的加密数据 by Hutool";
// 密钥必须为128bit
@@ -36,4 +37,18 @@ public class TEATest {
Assert.assertEquals(data, decryptStr);
}
@Test
public void xxteaTest() {
String data = "测试的加密数据 by Hutool";
// 密钥必须为128bit
final XXTEA tea = new XXTEA("MyPassword123456".getBytes());
final byte[] encrypt = tea.encrypt(data);
// 解密
final String decryptStr = tea.decryptStr(encrypt);
Assert.assertEquals(data, decryptStr);
}
}