|
@@ -1,11 +1,5 @@
|
|
|
package cn.hutool.crypto.symmetric;
|
|
package cn.hutool.crypto.symmetric;
|
|
|
|
|
|
|
|
-import java.io.Serializable;
|
|
|
|
|
-import java.nio.charset.Charset;
|
|
|
|
|
-import java.util.concurrent.locks.ReentrantReadWriteLock;
|
|
|
|
|
-import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
|
|
|
|
|
-import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
|
|
|
|
|
-
|
|
|
|
|
import cn.hutool.core.codec.Base64;
|
|
import cn.hutool.core.codec.Base64;
|
|
|
import cn.hutool.core.util.CharsetUtil;
|
|
import cn.hutool.core.util.CharsetUtil;
|
|
|
import cn.hutool.core.util.HexUtil;
|
|
import cn.hutool.core.util.HexUtil;
|
|
@@ -13,6 +7,12 @@ import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.crypto.CryptoException;
|
|
import cn.hutool.crypto.CryptoException;
|
|
|
import cn.hutool.crypto.SecureUtil;
|
|
import cn.hutool.crypto.SecureUtil;
|
|
|
|
|
|
|
|
|
|
+import java.io.Serializable;
|
|
|
|
|
+import java.nio.charset.Charset;
|
|
|
|
|
+import java.util.concurrent.locks.ReentrantReadWriteLock;
|
|
|
|
|
+import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
|
|
|
|
|
+import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* RC4加密解密算法实现<br>
|
|
* RC4加密解密算法实现<br>
|
|
|
* 来自:https://github.com/xSAVIKx/RC4-cipher/blob/master/src/main/java/com/github/xsavikx/rc4/RC4.java
|
|
* 来自:https://github.com/xSAVIKx/RC4-cipher/blob/master/src/main/java/com/github/xsavikx/rc4/RC4.java
|
|
@@ -103,6 +103,7 @@ public class RC4 implements Serializable {
|
|
|
*
|
|
*
|
|
|
* @param data 被加密的字符串
|
|
* @param data 被加密的字符串
|
|
|
* @return 加密后的Hex
|
|
* @return 加密后的Hex
|
|
|
|
|
+ * @since 5.4.4
|
|
|
*/
|
|
*/
|
|
|
public String encryptHex(String data) {
|
|
public String encryptHex(String data) {
|
|
|
return HexUtil.encodeHexStr(encrypt(data));
|
|
return HexUtil.encodeHexStr(encrypt(data));
|
|
@@ -126,6 +127,7 @@ public class RC4 implements Serializable {
|
|
|
*
|
|
*
|
|
|
* @param data 被加密的字符串
|
|
* @param data 被加密的字符串
|
|
|
* @return 加密后的Base64
|
|
* @return 加密后的Base64
|
|
|
|
|
+ * @since 5.4.4
|
|
|
*/
|
|
*/
|
|
|
public String encryptBase64(String data) {
|
|
public String encryptBase64(String data) {
|
|
|
return Base64.encode(encrypt(data));
|
|
return Base64.encode(encrypt(data));
|
|
@@ -159,6 +161,7 @@ public class RC4 implements Serializable {
|
|
|
*
|
|
*
|
|
|
* @param message 消息
|
|
* @param message 消息
|
|
|
* @return 明文
|
|
* @return 明文
|
|
|
|
|
+ * @since 5.4.4
|
|
|
*/
|
|
*/
|
|
|
public String decrypt(String message) {
|
|
public String decrypt(String message) {
|
|
|
return decrypt(SecureUtil.decode(message));
|
|
return decrypt(SecureUtil.decode(message));
|
|
@@ -170,6 +173,7 @@ public class RC4 implements Serializable {
|
|
|
* @param message 明文
|
|
* @param message 明文
|
|
|
* @param charset 解密后的charset
|
|
* @param charset 解密后的charset
|
|
|
* @return 明文
|
|
* @return 明文
|
|
|
|
|
+ * @since 5.4.4
|
|
|
*/
|
|
*/
|
|
|
public String decrypt(String message, Charset charset) {
|
|
public String decrypt(String message, Charset charset) {
|
|
|
return StrUtil.str(decrypt(message), charset);
|
|
return StrUtil.str(decrypt(message), charset);
|