mirror of
https://gitee.com/dromara/hutool.git
synced 2025-06-28 13:34:09 +08:00
add test
This commit is contained in:
parent
1fba8c75b0
commit
899f1384f6
@ -0,0 +1,39 @@
|
|||||||
|
package cn.hutool.crypto.test.symmetric;
|
||||||
|
|
||||||
|
import cn.hutool.crypto.symmetric.SymmetricCrypto;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TEA(Tiny Encryption Algorithm)和 XTEA算法单元测试
|
||||||
|
*/
|
||||||
|
public class TEATest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void teaTest(){
|
||||||
|
String data = "测试的加密数据 by Hutool";
|
||||||
|
|
||||||
|
// 密钥必须为128bit
|
||||||
|
final SymmetricCrypto tea = new SymmetricCrypto("TEA", "MyPassword123456".getBytes());
|
||||||
|
final byte[] encrypt = tea.encrypt(data);
|
||||||
|
|
||||||
|
// 解密
|
||||||
|
final String decryptStr = tea.decryptStr(encrypt);
|
||||||
|
|
||||||
|
Assert.assertEquals(data, decryptStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void xteaTest(){
|
||||||
|
String data = "测试的加密数据 by Hutool";
|
||||||
|
|
||||||
|
// 密钥必须为128bit
|
||||||
|
final SymmetricCrypto tea = new SymmetricCrypto("XTEA", "MyPassword123456".getBytes());
|
||||||
|
final byte[] encrypt = tea.encrypt(data);
|
||||||
|
|
||||||
|
// 解密
|
||||||
|
final String decryptStr = tea.decryptStr(encrypt);
|
||||||
|
|
||||||
|
Assert.assertEquals(data, decryptStr);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user