mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
RC4特性增强
This commit is contained in:
parent
543bd0b45f
commit
4df1073e01
@ -1,10 +1,14 @@
|
||||
package cn.hutool.crypto.test.symmetric;
|
||||
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.crypto.symmetric.RC4;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class RC4Test {
|
||||
|
||||
@Test
|
||||
@ -36,4 +40,35 @@ public class RC4Test {
|
||||
String msg2 = rc4.decrypt(crypt2);
|
||||
Assert.assertEquals(message2, msg2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecryptWithHexMessage() {
|
||||
String message = "这是第一个用来测试密文为十六进制字符串的消息!";
|
||||
String key = "生成一个密钥";
|
||||
RC4 rc4 = new RC4(key);
|
||||
String encryptHex = rc4.encryptHex(message, CharsetUtil.CHARSET_UTF_8);
|
||||
String msg = rc4.decrypt(encryptHex);
|
||||
Assert.assertEquals(message, msg);
|
||||
|
||||
String message2 = "这是第二个用来测试密文为十六进制字符串的消息!";
|
||||
String encryptHex2 = rc4.encryptHex(message2);
|
||||
String msg2 = rc4.decrypt(encryptHex2);
|
||||
Assert.assertEquals(message2, msg2);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDecryptWithBase64Message() {
|
||||
String message = "这是第一个用来测试密文为Base64编码的消息!";
|
||||
String key = "生成一个密钥";
|
||||
RC4 rc4 = new RC4(key);
|
||||
String encryptHex = rc4.encryptBase64(message, CharsetUtil.CHARSET_UTF_8);
|
||||
String msg = rc4.decrypt(encryptHex);
|
||||
Assert.assertEquals(message, msg);
|
||||
|
||||
String message2 = "这是第一个用来测试密文为Base64编码的消息!";
|
||||
String encryptHex2 = rc4.encryptBase64(message2);
|
||||
String msg2 = rc4.decrypt(encryptHex2);
|
||||
Assert.assertEquals(message2, msg2);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user