mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add des test
This commit is contained in:
parent
61e4f67e02
commit
95561c1410
@ -0,0 +1,39 @@
|
|||||||
|
package cn.hutool.crypto.test;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.crypto.Mode;
|
||||||
|
import cn.hutool.crypto.Padding;
|
||||||
|
import cn.hutool.crypto.SecureUtil;
|
||||||
|
import cn.hutool.crypto.symmetric.DES;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class DesTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void encryptDecryptTest(){
|
||||||
|
String content = "我是一个测试的test字符串123";
|
||||||
|
final DES des = SecureUtil.des();
|
||||||
|
|
||||||
|
final String encryptHex = des.encryptHex(content);
|
||||||
|
final String result = des.decryptStr(encryptHex);
|
||||||
|
|
||||||
|
Assert.assertEquals(content, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void encryptDecryptWithCustomTest(){
|
||||||
|
String content = "我是一个测试的test字符串123";
|
||||||
|
final DES des = new DES(
|
||||||
|
Mode.CTS,
|
||||||
|
Padding.PKCS5Padding,
|
||||||
|
StrUtil.bytes("12345678"),
|
||||||
|
StrUtil.bytes("11223344")
|
||||||
|
);
|
||||||
|
|
||||||
|
final String encryptHex = des.encryptHex(content);
|
||||||
|
final String result = des.decryptStr(encryptHex);
|
||||||
|
|
||||||
|
Assert.assertEquals(content, result);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user