mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.crypto;
|
||||
|
||||
import cn.hutool.core.exceptions.ExceptionUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
||||
/**
|
||||
* 加密异常
|
||||
|
@@ -7,7 +7,7 @@ import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.asymmetric.AsymmetricAlgorithm;
|
||||
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
|
||||
|
||||
|
@@ -2,7 +2,7 @@ package cn.hutool.crypto;
|
||||
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import org.bouncycastle.util.io.pem.PemObject;
|
||||
import org.bouncycastle.util.io.pem.PemObjectGenerator;
|
||||
import org.bouncycastle.util.io.pem.PemReader;
|
||||
|
@@ -4,7 +4,7 @@ import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import cn.hutool.core.codec.HexUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.asymmetric.AsymmetricAlgorithm;
|
||||
import cn.hutool.crypto.asymmetric.RSA;
|
||||
import cn.hutool.crypto.asymmetric.Sign;
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.crypto;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.asymmetric.Sign;
|
||||
import cn.hutool.crypto.asymmetric.SignAlgorithm;
|
||||
import cn.hutool.crypto.digest.DigestAlgorithm;
|
||||
|
@@ -5,7 +5,7 @@ import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
|
||||
import java.io.InputStream;
|
||||
@@ -80,7 +80,7 @@ public interface AsymmetricDecryptor {
|
||||
* @since 4.5.2
|
||||
*/
|
||||
default String decryptStr(String data, KeyType keyType) {
|
||||
return decryptStr(data, keyType, CharsetUtil.CHARSET_UTF_8);
|
||||
return decryptStr(data, keyType, CharsetUtil.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,7 +92,7 @@ public interface AsymmetricDecryptor {
|
||||
* @since 4.1.0
|
||||
*/
|
||||
default byte[] decryptFromBcd(String data, KeyType keyType) {
|
||||
return decryptFromBcd(data, keyType, CharsetUtil.CHARSET_UTF_8);
|
||||
return decryptFromBcd(data, keyType, CharsetUtil.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,6 +132,6 @@ public interface AsymmetricDecryptor {
|
||||
* @since 4.5.2
|
||||
*/
|
||||
default String decryptStrFromBcd(String data, KeyType keyType) {
|
||||
return decryptStrFromBcd(data, keyType, CharsetUtil.CHARSET_UTF_8);
|
||||
return decryptStrFromBcd(data, keyType, CharsetUtil.UTF_8);
|
||||
}
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.codec.HexUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
@@ -187,7 +187,7 @@ public interface AsymmetricEncryptor {
|
||||
* @since 4.1.0
|
||||
*/
|
||||
default String encryptBcd(String data, KeyType keyType) {
|
||||
return encryptBcd(data, keyType, CharsetUtil.CHARSET_UTF_8);
|
||||
return encryptBcd(data, keyType, CharsetUtil.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -5,7 +5,7 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.codec.HexUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.CryptoException;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
|
||||
@@ -207,7 +207,7 @@ public class Sign extends BaseAsymmetric<Sign> {
|
||||
* @since 5.7.0
|
||||
*/
|
||||
public byte[] sign(String data) {
|
||||
return sign(data, CharsetUtil.CHARSET_UTF_8);
|
||||
return sign(data, CharsetUtil.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -230,7 +230,7 @@ public class Sign extends BaseAsymmetric<Sign> {
|
||||
* @since 5.7.0
|
||||
*/
|
||||
public String signHex(String data) {
|
||||
return signHex(data, CharsetUtil.CHARSET_UTF_8);
|
||||
return signHex(data, CharsetUtil.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -437,7 +437,7 @@ public class BCrypt {
|
||||
rounds = Integer.parseInt(salt.substring(off, off + 2));
|
||||
|
||||
real_salt = salt.substring(off + 3, off + 25);
|
||||
byte[] passwordb = (password + (minor >= 'a' ? "\000" : "")).getBytes(CharsetUtil.CHARSET_UTF_8);
|
||||
byte[] passwordb = (password + (minor >= 'a' ? "\000" : "")).getBytes(CharsetUtil.UTF_8);
|
||||
saltb = decodeBase64(real_salt, BCRYPT_SALT_LEN);
|
||||
|
||||
bcrypt = new BCrypt();
|
||||
@@ -521,8 +521,8 @@ public class BCrypt {
|
||||
// 生成密文时错误直接返回false issue#1377@Github
|
||||
return false;
|
||||
}
|
||||
hashed_bytes = hashed.getBytes(CharsetUtil.CHARSET_UTF_8);
|
||||
try_bytes = try_pw.getBytes(CharsetUtil.CHARSET_UTF_8);
|
||||
hashed_bytes = hashed.getBytes(CharsetUtil.UTF_8);
|
||||
try_bytes = try_pw.getBytes(CharsetUtil.UTF_8);
|
||||
if (hashed_bytes.length != try_bytes.length) {
|
||||
return false;
|
||||
}
|
||||
|
@@ -44,7 +44,7 @@ public class DigestUtil {
|
||||
* @return MD5摘要
|
||||
*/
|
||||
public static byte[] md5(String data) {
|
||||
return md5(data, CharsetUtil.UTF_8);
|
||||
return md5(data, CharsetUtil.NAME_UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,7 +107,7 @@ public class DigestUtil {
|
||||
* @return MD5摘要的16进制表示
|
||||
*/
|
||||
public static String md5Hex(String data) {
|
||||
return md5Hex(data, CharsetUtil.UTF_8);
|
||||
return md5Hex(data, CharsetUtil.NAME_UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -163,7 +163,7 @@ public class DigestUtil {
|
||||
* @since 4.6.0
|
||||
*/
|
||||
public static String md5Hex16(String data) {
|
||||
return md5Hex16(data, CharsetUtil.CHARSET_UTF_8);
|
||||
return md5Hex16(data, CharsetUtil.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -229,7 +229,7 @@ public class DigestUtil {
|
||||
* @return MD5摘要
|
||||
*/
|
||||
public static byte[] sha1(String data) {
|
||||
return sha1(data, CharsetUtil.UTF_8);
|
||||
return sha1(data, CharsetUtil.NAME_UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -280,7 +280,7 @@ public class DigestUtil {
|
||||
* @return SHA-1摘要的16进制表示
|
||||
*/
|
||||
public static String sha1Hex(String data) {
|
||||
return sha1Hex(data, CharsetUtil.UTF_8);
|
||||
return sha1Hex(data, CharsetUtil.NAME_UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -336,7 +336,7 @@ public class DigestUtil {
|
||||
* @since 3.0.8
|
||||
*/
|
||||
public static byte[] sha256(String data) {
|
||||
return sha256(data, CharsetUtil.UTF_8);
|
||||
return sha256(data, CharsetUtil.NAME_UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -392,7 +392,7 @@ public class DigestUtil {
|
||||
* @since 3.0.8
|
||||
*/
|
||||
public static String sha256Hex(String data) {
|
||||
return sha256Hex(data, CharsetUtil.UTF_8);
|
||||
return sha256Hex(data, CharsetUtil.NAME_UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -6,7 +6,7 @@ import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.codec.HexUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.CryptoException;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
|
||||
@@ -189,7 +189,7 @@ public class Digester implements Serializable {
|
||||
* @return 摘要
|
||||
*/
|
||||
public byte[] digest(String data) {
|
||||
return digest(data, CharsetUtil.CHARSET_UTF_8);
|
||||
return digest(data, CharsetUtil.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -222,7 +222,7 @@ public class Digester implements Serializable {
|
||||
* @return 摘要
|
||||
*/
|
||||
public String digestHex(String data) {
|
||||
return digestHex(data, CharsetUtil.UTF_8);
|
||||
return digestHex(data, CharsetUtil.NAME_UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -5,7 +5,7 @@ import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.codec.HexUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.CryptoException;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
@@ -69,7 +69,7 @@ public class Mac implements Serializable {
|
||||
* @return 摘要
|
||||
*/
|
||||
public byte[] digest(String data) {
|
||||
return digest(data, CharsetUtil.CHARSET_UTF_8);
|
||||
return digest(data, CharsetUtil.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,7 +80,7 @@ public class Mac implements Serializable {
|
||||
* @return 摘要
|
||||
*/
|
||||
public String digestBase64(String data, boolean isUrlSafe) {
|
||||
return digestBase64(data, CharsetUtil.CHARSET_UTF_8, isUrlSafe);
|
||||
return digestBase64(data, CharsetUtil.UTF_8, isUrlSafe);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,7 +114,7 @@ public class Mac implements Serializable {
|
||||
* @return 摘要
|
||||
*/
|
||||
public String digestHex(String data) {
|
||||
return digestHex(data, CharsetUtil.CHARSET_UTF_8);
|
||||
return digestHex(data, CharsetUtil.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.crypto.digest.otp;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.digest.HmacAlgorithm;
|
||||
|
||||
import java.time.Duration;
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.crypto.symmetric;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.KeyUtil;
|
||||
import cn.hutool.crypto.Mode;
|
||||
import cn.hutool.crypto.Padding;
|
||||
|
@@ -3,7 +3,7 @@ package cn.hutool.crypto.symmetric;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.Mode;
|
||||
import cn.hutool.crypto.Padding;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
@@ -12,7 +12,7 @@ import cn.hutool.crypto.SecureUtil;
|
||||
* DES加密算法实现<br>
|
||||
* DES全称为Data Encryption Standard,即数据加密标准,是一种使用密钥加密的块算法<br>
|
||||
* Java中默认实现为:DES/CBC/PKCS5Padding
|
||||
*
|
||||
*
|
||||
* @author Looly
|
||||
* @since 3.0.8
|
||||
*/
|
||||
@@ -29,7 +29,7 @@ public class DES extends SymmetricCrypto {
|
||||
|
||||
/**
|
||||
* 构造,使用默认的DES/CBC/PKCS5Padding
|
||||
*
|
||||
*
|
||||
* @param key 密钥
|
||||
*/
|
||||
public DES(byte[] key) {
|
||||
@@ -38,7 +38,7 @@ public class DES extends SymmetricCrypto {
|
||||
|
||||
/**
|
||||
* 构造,使用随机密钥
|
||||
*
|
||||
*
|
||||
* @param mode 模式{@link Mode}
|
||||
* @param padding {@link Padding}补码方式
|
||||
*/
|
||||
@@ -48,7 +48,7 @@ public class DES extends SymmetricCrypto {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param mode 模式{@link Mode}
|
||||
* @param padding {@link Padding}补码方式
|
||||
* @param key 密钥,长度:8的倍数
|
||||
@@ -59,7 +59,7 @@ public class DES extends SymmetricCrypto {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param mode 模式{@link Mode}
|
||||
* @param padding {@link Padding}补码方式
|
||||
* @param key 密钥,长度:8的倍数
|
||||
@@ -72,7 +72,7 @@ public class DES extends SymmetricCrypto {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param mode 模式{@link Mode}
|
||||
* @param padding {@link Padding}补码方式
|
||||
* @param key 密钥,长度:8的倍数
|
||||
@@ -84,7 +84,7 @@ public class DES extends SymmetricCrypto {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param mode 模式{@link Mode}
|
||||
* @param padding {@link Padding}补码方式
|
||||
* @param key 密钥,长度:8的倍数
|
||||
@@ -97,7 +97,7 @@ public class DES extends SymmetricCrypto {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param mode 模式
|
||||
* @param padding 补码方式
|
||||
*/
|
||||
@@ -107,7 +107,7 @@ public class DES extends SymmetricCrypto {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param mode 模式
|
||||
* @param padding 补码方式
|
||||
* @param key 密钥,长度:8的倍数
|
||||
@@ -118,7 +118,7 @@ public class DES extends SymmetricCrypto {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param mode 模式
|
||||
* @param padding 补码方式
|
||||
* @param key 密钥,长度:8的倍数
|
||||
@@ -130,7 +130,7 @@ public class DES extends SymmetricCrypto {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param mode 模式
|
||||
* @param padding 补码方式
|
||||
* @param key 密钥,长度:8的倍数
|
||||
@@ -141,7 +141,7 @@ public class DES extends SymmetricCrypto {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param mode 模式
|
||||
* @param padding 补码方式
|
||||
* @param key 密钥,长度:8的倍数
|
||||
|
@@ -3,7 +3,7 @@ package cn.hutool.crypto.symmetric;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.Mode;
|
||||
import cn.hutool.crypto.Padding;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
@@ -13,7 +13,7 @@ import cn.hutool.crypto.SecureUtil;
|
||||
* 使用 168 位的密钥对资料进行三次加密的一种机制;它通常(但非始终)提供极其强大的安全性。<br>
|
||||
* 如果三个 56 位的子元素都相同,则三重 DES 向后兼容 DES。<br>
|
||||
* Java中默认实现为:DESede/ECB/PKCS5Padding
|
||||
*
|
||||
*
|
||||
* @author Looly
|
||||
* @since 3.3.0
|
||||
*/
|
||||
@@ -30,7 +30,7 @@ public class DESede extends SymmetricCrypto {
|
||||
|
||||
/**
|
||||
* 构造,使用默认的DESede/ECB/PKCS5Padding
|
||||
*
|
||||
*
|
||||
* @param key 密钥
|
||||
*/
|
||||
public DESede(byte[] key) {
|
||||
@@ -39,7 +39,7 @@ public class DESede extends SymmetricCrypto {
|
||||
|
||||
/**
|
||||
* 构造,使用随机密钥
|
||||
*
|
||||
*
|
||||
* @param mode 模式{@link Mode}
|
||||
* @param padding {@link Padding}补码方式
|
||||
*/
|
||||
@@ -49,7 +49,7 @@ public class DESede extends SymmetricCrypto {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param mode 模式{@link Mode}
|
||||
* @param padding {@link Padding}补码方式
|
||||
* @param key 密钥,长度24位
|
||||
@@ -60,7 +60,7 @@ public class DESede extends SymmetricCrypto {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param mode 模式{@link Mode}
|
||||
* @param padding {@link Padding}补码方式
|
||||
* @param key 密钥,长度24位
|
||||
@@ -73,7 +73,7 @@ public class DESede extends SymmetricCrypto {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param mode 模式{@link Mode}
|
||||
* @param padding {@link Padding}补码方式
|
||||
* @param key 密钥,长度24位
|
||||
@@ -85,7 +85,7 @@ public class DESede extends SymmetricCrypto {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param mode 模式{@link Mode}
|
||||
* @param padding {@link Padding}补码方式
|
||||
* @param key 密钥,长度24位
|
||||
@@ -98,7 +98,7 @@ public class DESede extends SymmetricCrypto {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param mode 模式
|
||||
* @param padding 补码方式
|
||||
*/
|
||||
@@ -108,7 +108,7 @@ public class DESede extends SymmetricCrypto {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param mode 模式
|
||||
* @param padding 补码方式
|
||||
* @param key 密钥,长度24位
|
||||
@@ -119,7 +119,7 @@ public class DESede extends SymmetricCrypto {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param mode 模式
|
||||
* @param padding 补码方式
|
||||
* @param key 密钥,长度24位
|
||||
@@ -131,7 +131,7 @@ public class DESede extends SymmetricCrypto {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param mode 模式
|
||||
* @param padding 补码方式
|
||||
* @param key 密钥
|
||||
@@ -142,7 +142,7 @@ public class DESede extends SymmetricCrypto {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param mode 模式
|
||||
* @param padding 补码方式
|
||||
* @param key 密钥
|
||||
|
@@ -3,7 +3,7 @@ package cn.hutool.crypto.symmetric;
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.codec.HexUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.CryptoException;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
|
||||
@@ -62,7 +62,7 @@ public class RC4 implements Serializable {
|
||||
* @throws CryptoException key长度小于5或者大于255抛出此异常
|
||||
*/
|
||||
public byte[] encrypt(String message) throws CryptoException {
|
||||
return encrypt(message, CharsetUtil.CHARSET_UTF_8);
|
||||
return encrypt(message, CharsetUtil.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,7 +154,7 @@ public class RC4 implements Serializable {
|
||||
* @throws CryptoException key长度小于5或者大于255抛出此异常
|
||||
*/
|
||||
public String decrypt(byte[] message) throws CryptoException {
|
||||
return decrypt(message, CharsetUtil.CHARSET_UTF_8);
|
||||
return decrypt(message, CharsetUtil.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.crypto.symmetric;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.Mode;
|
||||
import cn.hutool.crypto.Padding;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
|
@@ -7,7 +7,7 @@ import cn.hutool.core.lang.Opt;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.codec.HexUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.CipherMode;
|
||||
import cn.hutool.crypto.CipherWrapper;
|
||||
import cn.hutool.crypto.CryptoException;
|
||||
|
@@ -3,7 +3,7 @@ package cn.hutool.crypto.symmetric;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
|
||||
import java.io.InputStream;
|
||||
@@ -58,7 +58,7 @@ public interface SymmetricDecryptor {
|
||||
* @return 解密后的String
|
||||
*/
|
||||
default String decryptStr(byte[] bytes) {
|
||||
return decryptStr(bytes, CharsetUtil.CHARSET_UTF_8);
|
||||
return decryptStr(bytes, CharsetUtil.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,7 +89,7 @@ public interface SymmetricDecryptor {
|
||||
* @return 解密后的String
|
||||
*/
|
||||
default String decryptStr(String data) {
|
||||
return decryptStr(data, CharsetUtil.CHARSET_UTF_8);
|
||||
return decryptStr(data, CharsetUtil.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,6 +121,6 @@ public interface SymmetricDecryptor {
|
||||
* @return 解密后的String
|
||||
*/
|
||||
default String decryptStr(InputStream data) {
|
||||
return decryptStr(data, CharsetUtil.CHARSET_UTF_8);
|
||||
return decryptStr(data, CharsetUtil.UTF_8);
|
||||
}
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@ import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.codec.HexUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
@@ -136,7 +136,7 @@ public interface SymmetricEncryptor {
|
||||
* @return 加密后的bytes
|
||||
*/
|
||||
default byte[] encrypt(String data) {
|
||||
return encrypt(StrUtil.bytes(data, CharsetUtil.CHARSET_UTF_8));
|
||||
return encrypt(StrUtil.bytes(data, CharsetUtil.UTF_8));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -2,7 +2,7 @@ package cn.hutool.crypto.test;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.PemUtil;
|
||||
import cn.hutool.crypto.asymmetric.KeyType;
|
||||
import cn.hutool.crypto.asymmetric.RSA;
|
||||
|
@@ -32,7 +32,7 @@ public class SmTest {
|
||||
SM4 sm4 = SmUtil.sm4();
|
||||
|
||||
String encryptHex = sm4.encryptHex(content);
|
||||
String decryptStr = sm4.decryptStr(encryptHex, CharsetUtil.CHARSET_UTF_8);
|
||||
String decryptStr = sm4.decryptStr(encryptHex, CharsetUtil.UTF_8);
|
||||
|
||||
Assert.assertEquals(content, decryptStr);
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public class SmTest {
|
||||
sm4.setIv("aaaabbbb".getBytes());
|
||||
|
||||
String encryptHex = sm4.encryptHex(content);
|
||||
String decryptStr = sm4.decryptStr(encryptHex, CharsetUtil.CHARSET_UTF_8);
|
||||
String decryptStr = sm4.decryptStr(encryptHex, CharsetUtil.UTF_8);
|
||||
|
||||
Assert.assertEquals(content, decryptStr);
|
||||
}
|
||||
@@ -56,7 +56,7 @@ public class SmTest {
|
||||
Assert.assertEquals("SM4/ECB/PKCS5Padding", sm4.getCipher().getAlgorithm());
|
||||
|
||||
String encryptHex = sm4.encryptHex(content);
|
||||
String decryptStr = sm4.decryptStr(encryptHex, CharsetUtil.CHARSET_UTF_8);
|
||||
String decryptStr = sm4.decryptStr(encryptHex, CharsetUtil.UTF_8);
|
||||
Assert.assertEquals(content, decryptStr);
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public class SmTest {
|
||||
Assert.assertEquals("SM4/ECB/PKCS5Padding", sm4.getCipher().getAlgorithm());
|
||||
|
||||
String encryptHex = sm4.encryptHex(content);
|
||||
String decryptStr = sm4.decryptStr(encryptHex, CharsetUtil.CHARSET_UTF_8);
|
||||
String decryptStr = sm4.decryptStr(encryptHex, CharsetUtil.UTF_8);
|
||||
Assert.assertEquals(content, decryptStr);
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class SmTest {
|
||||
Assert.assertEquals("SM4", sm4.getCipher().getAlgorithm());
|
||||
|
||||
String encryptHex = sm4.encryptHex(content);
|
||||
String decryptStr = sm4.decryptStr(encryptHex, CharsetUtil.CHARSET_UTF_8);
|
||||
String decryptStr = sm4.decryptStr(encryptHex, CharsetUtil.UTF_8);
|
||||
Assert.assertEquals(content, decryptStr);
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.crypto.test.asymmetric;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.asymmetric.AsymmetricCrypto;
|
||||
import cn.hutool.crypto.asymmetric.ECIES;
|
||||
import cn.hutool.crypto.asymmetric.KeyType;
|
||||
|
@@ -5,7 +5,7 @@ import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.codec.HexUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.KeyUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.hutool.crypto.asymmetric.AsymmetricAlgorithm;
|
||||
@@ -42,14 +42,14 @@ public class RSATest {
|
||||
RSA rsa = SecureUtil.rsa(privateKey, publicKey);
|
||||
|
||||
// 公钥加密,私钥解密
|
||||
byte[] encrypt = rsa.encrypt(StrUtil.bytes("我是一段测试aaaa", CharsetUtil.CHARSET_UTF_8), KeyType.PublicKey);
|
||||
byte[] encrypt = rsa.encrypt(StrUtil.bytes("我是一段测试aaaa", CharsetUtil.UTF_8), KeyType.PublicKey);
|
||||
byte[] decrypt = rsa.decrypt(encrypt, KeyType.PrivateKey);
|
||||
Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt, CharsetUtil.CHARSET_UTF_8));
|
||||
Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt, CharsetUtil.UTF_8));
|
||||
|
||||
// 私钥加密,公钥解密
|
||||
byte[] encrypt2 = rsa.encrypt(StrUtil.bytes("我是一段测试aaaa", CharsetUtil.CHARSET_UTF_8), KeyType.PrivateKey);
|
||||
byte[] encrypt2 = rsa.encrypt(StrUtil.bytes("我是一段测试aaaa", CharsetUtil.UTF_8), KeyType.PrivateKey);
|
||||
byte[] decrypt2 = rsa.decrypt(encrypt2, KeyType.PublicKey);
|
||||
Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt2, CharsetUtil.CHARSET_UTF_8));
|
||||
Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt2, CharsetUtil.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -63,15 +63,15 @@ public class RSATest {
|
||||
Assert.assertNotNull(rsa.getPrivateKeyBase64());
|
||||
|
||||
// 公钥加密,私钥解密
|
||||
byte[] encrypt = rsa.encrypt(StrUtil.bytes("我是一段测试aaaa", CharsetUtil.CHARSET_UTF_8), KeyType.PublicKey);
|
||||
byte[] encrypt = rsa.encrypt(StrUtil.bytes("我是一段测试aaaa", CharsetUtil.UTF_8), KeyType.PublicKey);
|
||||
|
||||
byte[] decrypt = rsa.decrypt(encrypt, KeyType.PrivateKey);
|
||||
Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt, CharsetUtil.CHARSET_UTF_8));
|
||||
Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt, CharsetUtil.UTF_8));
|
||||
|
||||
// 私钥加密,公钥解密
|
||||
byte[] encrypt2 = rsa.encrypt(StrUtil.bytes("我是一段测试aaaa", CharsetUtil.CHARSET_UTF_8), KeyType.PrivateKey);
|
||||
byte[] encrypt2 = rsa.encrypt(StrUtil.bytes("我是一段测试aaaa", CharsetUtil.UTF_8), KeyType.PrivateKey);
|
||||
byte[] decrypt2 = rsa.decrypt(encrypt2, KeyType.PublicKey);
|
||||
Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt2, CharsetUtil.CHARSET_UTF_8));
|
||||
Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt2, CharsetUtil.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,15 +85,15 @@ public class RSATest {
|
||||
Assert.assertNotNull(rsa.getPrivateKeyBase64());
|
||||
|
||||
// 公钥加密,私钥解密
|
||||
byte[] encrypt = rsa.encrypt(StrUtil.bytes("我是一段测试aaaa", CharsetUtil.CHARSET_UTF_8), KeyType.PublicKey);
|
||||
byte[] encrypt = rsa.encrypt(StrUtil.bytes("我是一段测试aaaa", CharsetUtil.UTF_8), KeyType.PublicKey);
|
||||
|
||||
byte[] decrypt = rsa.decrypt(encrypt, KeyType.PrivateKey);
|
||||
Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt, CharsetUtil.CHARSET_UTF_8));
|
||||
Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt, CharsetUtil.UTF_8));
|
||||
|
||||
// 私钥加密,公钥解密
|
||||
byte[] encrypt2 = rsa.encrypt(StrUtil.bytes("我是一段测试aaaa", CharsetUtil.CHARSET_UTF_8), KeyType.PrivateKey);
|
||||
byte[] encrypt2 = rsa.encrypt(StrUtil.bytes("我是一段测试aaaa", CharsetUtil.UTF_8), KeyType.PrivateKey);
|
||||
byte[] decrypt2 = rsa.decrypt(encrypt2, KeyType.PublicKey);
|
||||
Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt2, CharsetUtil.CHARSET_UTF_8));
|
||||
Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt2, CharsetUtil.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -107,15 +107,15 @@ public class RSATest {
|
||||
Assert.assertNotNull(rsa.getPrivateKeyBase64());
|
||||
|
||||
// 公钥加密,私钥解密
|
||||
byte[] encrypt = rsa.encrypt(StrUtil.bytes("我是一段测试aaaa", CharsetUtil.CHARSET_UTF_8), KeyType.PublicKey);
|
||||
byte[] encrypt = rsa.encrypt(StrUtil.bytes("我是一段测试aaaa", CharsetUtil.UTF_8), KeyType.PublicKey);
|
||||
|
||||
byte[] decrypt = rsa.decrypt(encrypt, KeyType.PrivateKey);
|
||||
Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt, CharsetUtil.CHARSET_UTF_8));
|
||||
Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt, CharsetUtil.UTF_8));
|
||||
|
||||
// 私钥加密,公钥解密
|
||||
byte[] encrypt2 = rsa.encrypt(StrUtil.bytes("我是一段测试aaaa", CharsetUtil.CHARSET_UTF_8), KeyType.PrivateKey);
|
||||
byte[] encrypt2 = rsa.encrypt(StrUtil.bytes("我是一段测试aaaa", CharsetUtil.UTF_8), KeyType.PrivateKey);
|
||||
byte[] decrypt2 = rsa.decrypt(encrypt2, KeyType.PublicKey);
|
||||
Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt2, CharsetUtil.CHARSET_UTF_8));
|
||||
Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt2, CharsetUtil.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -130,14 +130,14 @@ public class RSATest {
|
||||
Assert.assertNotNull(rsa.getPrivateKeyBase64());
|
||||
|
||||
// 公钥加密,私钥解密
|
||||
byte[] encrypt = rsa.encrypt(StrUtil.bytes("我是一段测试aaaa", CharsetUtil.CHARSET_UTF_8), KeyType.PublicKey);
|
||||
byte[] encrypt = rsa.encrypt(StrUtil.bytes("我是一段测试aaaa", CharsetUtil.UTF_8), KeyType.PublicKey);
|
||||
byte[] decrypt = rsa.decrypt(encrypt, KeyType.PrivateKey);
|
||||
Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt, CharsetUtil.CHARSET_UTF_8));
|
||||
Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt, CharsetUtil.UTF_8));
|
||||
|
||||
// 私钥加密,公钥解密
|
||||
byte[] encrypt2 = rsa.encrypt(StrUtil.bytes("我是一段测试aaaa", CharsetUtil.CHARSET_UTF_8), KeyType.PrivateKey);
|
||||
byte[] encrypt2 = rsa.encrypt(StrUtil.bytes("我是一段测试aaaa", CharsetUtil.UTF_8), KeyType.PrivateKey);
|
||||
byte[] decrypt2 = rsa.decrypt(encrypt2, KeyType.PublicKey);
|
||||
Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt2, CharsetUtil.CHARSET_UTF_8));
|
||||
Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt2, CharsetUtil.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -200,7 +200,7 @@ public class RSATest {
|
||||
byte[] aByte = HexUtil.decodeHex(a);
|
||||
byte[] decrypt = rsa.decrypt(aByte, KeyType.PrivateKey);
|
||||
|
||||
Assert.assertEquals("虎头闯杭州,多抬头看天,切勿只管种地", StrUtil.str(decrypt, CharsetUtil.CHARSET_UTF_8));
|
||||
Assert.assertEquals("虎头闯杭州,多抬头看天,切勿只管种地", StrUtil.str(decrypt, CharsetUtil.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -3,7 +3,7 @@ package cn.hutool.crypto.test.asymmetric;
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.codec.HexUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.ECKeyUtil;
|
||||
import cn.hutool.crypto.KeyUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
@@ -54,9 +54,9 @@ public class SM2Test {
|
||||
sm2.setMode(SM2Engine.Mode.C1C2C3);
|
||||
|
||||
// 公钥加密,私钥解密
|
||||
byte[] encrypt = sm2.encrypt(StrUtil.bytes("我是一段测试aaaa", CharsetUtil.CHARSET_UTF_8), KeyType.PublicKey);
|
||||
byte[] encrypt = sm2.encrypt(StrUtil.bytes("我是一段测试aaaa", CharsetUtil.UTF_8), KeyType.PublicKey);
|
||||
byte[] decrypt = sm2.decrypt(encrypt, KeyType.PrivateKey);
|
||||
Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt, CharsetUtil.CHARSET_UTF_8));
|
||||
Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt, CharsetUtil.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -70,9 +70,9 @@ public class SM2Test {
|
||||
Assert.assertNotNull(sm2.getPrivateKeyBase64());
|
||||
|
||||
// 公钥加密,私钥解密
|
||||
byte[] encrypt = sm2.encrypt(StrUtil.bytes("我是一段测试aaaa", CharsetUtil.CHARSET_UTF_8), KeyType.PublicKey);
|
||||
byte[] encrypt = sm2.encrypt(StrUtil.bytes("我是一段测试aaaa", CharsetUtil.UTF_8), KeyType.PublicKey);
|
||||
byte[] decrypt = sm2.decrypt(encrypt, KeyType.PrivateKey);
|
||||
Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt, CharsetUtil.CHARSET_UTF_8));
|
||||
Assert.assertEquals("我是一段测试aaaa", StrUtil.str(decrypt, CharsetUtil.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package cn.hutool.crypto.test.asymmetric;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.hutool.crypto.asymmetric.Sign;
|
||||
import cn.hutool.crypto.asymmetric.SignAlgorithm;
|
||||
|
@@ -14,40 +14,40 @@ import cn.hutool.crypto.digest.Digester;
|
||||
*
|
||||
*/
|
||||
public class DigestTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void digesterTest(){
|
||||
String testStr = "test中文";
|
||||
|
||||
|
||||
Digester md5 = new Digester(DigestAlgorithm.MD5);
|
||||
String digestHex = md5.digestHex(testStr);
|
||||
Assert.assertEquals("5393554e94bf0eb6436f240a4fd71282", digestHex);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void md5Test(){
|
||||
String testStr = "test中文";
|
||||
|
||||
|
||||
String md5Hex1 = DigestUtil.md5Hex(testStr);
|
||||
Assert.assertEquals("5393554e94bf0eb6436f240a4fd71282", md5Hex1);
|
||||
|
||||
String md5Hex2 = DigestUtil.md5Hex(IoUtil.toStream(testStr, CharsetUtil.CHARSET_UTF_8));
|
||||
|
||||
String md5Hex2 = DigestUtil.md5Hex(IoUtil.toStream(testStr, CharsetUtil.UTF_8));
|
||||
Assert.assertEquals("5393554e94bf0eb6436f240a4fd71282", md5Hex2);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void md5WithSaltTest(){
|
||||
String testStr = "test中文";
|
||||
|
||||
|
||||
Digester md5 = new Digester(DigestAlgorithm.MD5);
|
||||
|
||||
|
||||
//加盐
|
||||
md5.setSalt("saltTest".getBytes());
|
||||
String md5Hex1 = md5.digestHex(testStr);
|
||||
Assert.assertEquals("762f7335200299dfa09bebbb601a5bc6", md5Hex1);
|
||||
String md5Hex2 = md5.digestHex(IoUtil.toUtf8Stream(testStr));
|
||||
Assert.assertEquals("762f7335200299dfa09bebbb601a5bc6", md5Hex2);
|
||||
|
||||
|
||||
//重复2次
|
||||
md5.setDigestCount(2);
|
||||
String md5Hex3 = md5.digestHex(testStr);
|
||||
@@ -55,18 +55,18 @@ public class DigestTest {
|
||||
String md5Hex4 = md5.digestHex(IoUtil.toUtf8Stream(testStr));
|
||||
Assert.assertEquals("2b0616296f6755d25efc07f90afe9684", md5Hex4);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void sha1Test(){
|
||||
String testStr = "test中文";
|
||||
|
||||
|
||||
String sha1Hex1 = DigestUtil.sha1Hex(testStr);
|
||||
Assert.assertEquals("ecabf586cef0d3b11c56549433ad50b81110a836", sha1Hex1);
|
||||
|
||||
String sha1Hex2 = DigestUtil.sha1Hex(IoUtil.toStream(testStr, CharsetUtil.CHARSET_UTF_8));
|
||||
|
||||
String sha1Hex2 = DigestUtil.sha1Hex(IoUtil.toStream(testStr, CharsetUtil.UTF_8));
|
||||
Assert.assertEquals("ecabf586cef0d3b11c56549433ad50b81110a836", sha1Hex2);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void hash256Test() {
|
||||
String testStr = "Test中文";
|
||||
|
@@ -29,7 +29,7 @@ public class HmacTest {
|
||||
String macHex1 = mac.digestHex(testStr);
|
||||
Assert.assertEquals("b977f4b13f93f549e06140971bded384", macHex1);
|
||||
|
||||
String macHex2 = mac.digestHex(IoUtil.toStream(testStr, CharsetUtil.CHARSET_UTF_8));
|
||||
String macHex2 = mac.digestHex(IoUtil.toStream(testStr, CharsetUtil.UTF_8));
|
||||
Assert.assertEquals("b977f4b13f93f549e06140971bded384", macHex2);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class HmacTest {
|
||||
String macHex1 = mac.digestHex(testStr);
|
||||
Assert.assertEquals("b977f4b13f93f549e06140971bded384", macHex1);
|
||||
|
||||
String macHex2 = mac.digestHex(IoUtil.toStream(testStr, CharsetUtil.CHARSET_UTF_8));
|
||||
String macHex2 = mac.digestHex(IoUtil.toStream(testStr, CharsetUtil.UTF_8));
|
||||
Assert.assertEquals("b977f4b13f93f549e06140971bded384", macHex2);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class HmacTest {
|
||||
String macHex1 = mac.digestHex(testStr);
|
||||
Assert.assertEquals("1dd68d2f119d5640f0d416e99d3f42408b88d511", macHex1);
|
||||
|
||||
String macHex2 = mac.digestHex(IoUtil.toStream(testStr, CharsetUtil.CHARSET_UTF_8));
|
||||
String macHex2 = mac.digestHex(IoUtil.toStream(testStr, CharsetUtil.UTF_8));
|
||||
Assert.assertEquals("1dd68d2f119d5640f0d416e99d3f42408b88d511", macHex2);
|
||||
}
|
||||
|
||||
|
@@ -24,7 +24,7 @@ public class ChaCha20Test {
|
||||
// 加密为16进制表示
|
||||
String encryptHex = chacha.encryptHex(content);
|
||||
// 解密为字符串
|
||||
String decryptStr = chacha.decryptStr(encryptHex, CharsetUtil.CHARSET_UTF_8);
|
||||
String decryptStr = chacha.decryptStr(encryptHex, CharsetUtil.UTF_8);
|
||||
|
||||
Assert.assertEquals(content, decryptStr);
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package cn.hutool.crypto.test.symmetric;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.Mode;
|
||||
import cn.hutool.crypto.Padding;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
|
@@ -7,7 +7,7 @@ import org.junit.Test;
|
||||
import cn.hutool.crypto.symmetric.RC4;
|
||||
|
||||
public class RC4Test {
|
||||
|
||||
|
||||
@Test
|
||||
public void testCryptMessage() {
|
||||
String key = "This is pretty long key";
|
||||
@@ -16,7 +16,7 @@ public class RC4Test {
|
||||
byte[] crypt = rc4.encrypt(message);
|
||||
String msg = rc4.decrypt(crypt);
|
||||
Assert.assertEquals(message, msg);
|
||||
|
||||
|
||||
String message2 = "Hello, World, this is megssage 2";
|
||||
byte[] crypt2 = rc4.encrypt(message2);
|
||||
String msg2 = rc4.decrypt(crypt2);
|
||||
@@ -31,7 +31,7 @@ public class RC4Test {
|
||||
byte[] crypt = rc4.encrypt(message);
|
||||
String msg = rc4.decrypt(crypt);
|
||||
Assert.assertEquals(message, msg);
|
||||
|
||||
|
||||
String message2 = "这是第二个中文消息!";
|
||||
byte[] crypt2 = rc4.encrypt(message2);
|
||||
String msg2 = rc4.decrypt(crypt2);
|
||||
@@ -43,7 +43,7 @@ public class RC4Test {
|
||||
String message = "这是第一个用来测试密文为十六进制字符串的消息!";
|
||||
String key = "生成一个密钥";
|
||||
RC4 rc4 = new RC4(key);
|
||||
String encryptHex = rc4.encryptHex(message, CharsetUtil.CHARSET_UTF_8);
|
||||
String encryptHex = rc4.encryptHex(message, CharsetUtil.UTF_8);
|
||||
String msg = rc4.decrypt(encryptHex);
|
||||
Assert.assertEquals(message, msg);
|
||||
|
||||
@@ -59,7 +59,7 @@ public class RC4Test {
|
||||
String message = "这是第一个用来测试密文为Base64编码的消息!";
|
||||
String key = "生成一个密钥";
|
||||
RC4 rc4 = new RC4(key);
|
||||
String encryptHex = rc4.encryptBase64(message, CharsetUtil.CHARSET_UTF_8);
|
||||
String encryptHex = rc4.encryptBase64(message, CharsetUtil.UTF_8);
|
||||
String msg = rc4.decrypt(encryptHex);
|
||||
Assert.assertEquals(message, msg);
|
||||
|
||||
|
@@ -3,7 +3,7 @@ package cn.hutool.crypto.test.symmetric;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.CipherMode;
|
||||
import cn.hutool.crypto.KeyUtil;
|
||||
import cn.hutool.crypto.Mode;
|
||||
@@ -43,12 +43,12 @@ public class SymmetricTest {
|
||||
// 解密
|
||||
byte[] decrypt = aes.decrypt(encrypt);
|
||||
|
||||
Assert.assertEquals(content, StrUtil.str(decrypt, CharsetUtil.CHARSET_UTF_8));
|
||||
Assert.assertEquals(content, StrUtil.str(decrypt, CharsetUtil.UTF_8));
|
||||
|
||||
// 加密为16进制表示
|
||||
String encryptHex = aes.encryptHex(content);
|
||||
// 解密为字符串
|
||||
String decryptStr = aes.decryptStr(encryptHex, CharsetUtil.CHARSET_UTF_8);
|
||||
String decryptStr = aes.decryptStr(encryptHex, CharsetUtil.UTF_8);
|
||||
|
||||
Assert.assertEquals(content, decryptStr);
|
||||
}
|
||||
@@ -73,7 +73,7 @@ public class SymmetricTest {
|
||||
// 加密为16进制表示
|
||||
String encryptHex = aes.encryptHex(content);
|
||||
// 解密为字符串
|
||||
String decryptStr = aes.decryptStr(encryptHex, CharsetUtil.CHARSET_UTF_8);
|
||||
String decryptStr = aes.decryptStr(encryptHex, CharsetUtil.UTF_8);
|
||||
|
||||
Assert.assertEquals(content, decryptStr);
|
||||
}
|
||||
@@ -94,7 +94,7 @@ public class SymmetricTest {
|
||||
// 加密为16进制表示
|
||||
String encryptHex = aes.encryptHex(content);
|
||||
// 解密为字符串
|
||||
String decryptStr = aes.decryptStr(encryptHex, CharsetUtil.CHARSET_UTF_8);
|
||||
String decryptStr = aes.decryptStr(encryptHex, CharsetUtil.UTF_8);
|
||||
|
||||
Assert.assertEquals(content, decryptStr);
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@ public class ZucTest {
|
||||
|
||||
String msg = RandomUtil.randomString(500);
|
||||
byte[] crypt2 = zuc.encrypt(msg);
|
||||
String msg2 = zuc.decryptStr(crypt2, CharsetUtil.CHARSET_UTF_8);
|
||||
String msg2 = zuc.decryptStr(crypt2, CharsetUtil.UTF_8);
|
||||
Assert.assertEquals(msg, msg2);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class ZucTest {
|
||||
|
||||
String msg = RandomUtil.randomString(500);
|
||||
byte[] crypt2 = zuc.encrypt(msg);
|
||||
String msg2 = zuc.decryptStr(crypt2, CharsetUtil.CHARSET_UTF_8);
|
||||
String msg2 = zuc.decryptStr(crypt2, CharsetUtil.UTF_8);
|
||||
Assert.assertEquals(msg, msg2);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user