|
|
@@ -5,8 +5,9 @@ import cn.hutool.core.util.ArrayUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.crypto.SecureUtil;
|
|
|
import cn.hutool.crypto.SmUtil;
|
|
|
-import cn.hutool.crypto.asymmetric.*;
|
|
|
-import cn.hutool.crypto.digest.MD5;
|
|
|
+import cn.hutool.crypto.asymmetric.KeyType;
|
|
|
+import cn.hutool.crypto.asymmetric.RSA;
|
|
|
+import cn.hutool.crypto.asymmetric.SM2;
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
@@ -116,6 +117,7 @@ public class EncryptUtils {
|
|
|
if (StrUtil.isBlank(password)) {
|
|
|
throw new IllegalArgumentException("DESede需要传入秘钥信息");
|
|
|
}
|
|
|
+ byte[] temp = password.getBytes(StandardCharsets.UTF_8);
|
|
|
return SecureUtil.desede(password.getBytes(StandardCharsets.UTF_8)).decryptStr(data, StandardCharsets.UTF_8);
|
|
|
}
|
|
|
/**
|
|
|
@@ -305,6 +307,20 @@ public class EncryptUtils {
|
|
|
RSA rsa = SecureUtil.rsa(privateKey, null);
|
|
|
return rsa.decryptStr(data, KeyType.PrivateKey, StandardCharsets.UTF_8);
|
|
|
}
|
|
|
+ /**
|
|
|
+ * rsa私钥解密
|
|
|
+ *
|
|
|
+ * @param data 待加密数据
|
|
|
+ * @param publicKey 公钥
|
|
|
+ * @return 解密后字符串
|
|
|
+ */
|
|
|
+ public static String decryptByRsaPublicKey(String data, String publicKey) {
|
|
|
+ if (StrUtil.isBlank(publicKey)) {
|
|
|
+ throw new IllegalArgumentException("RSA需要传入公钥进行解密");
|
|
|
+ }
|
|
|
+ RSA rsa = SecureUtil.rsa(null, publicKey);
|
|
|
+ return rsa.decryptStr(data, KeyType.PublicKey, StandardCharsets.UTF_8);
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* md5加密
|
|
|
@@ -335,20 +351,13 @@ public class EncryptUtils {
|
|
|
public static String encryptBySm3(String data) {
|
|
|
return SmUtil.sm3(data);
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * DESede(3Des解密)解密
|
|
|
- *
|
|
|
- * @param data 待解密数据
|
|
|
- * @param password 秘钥字符串
|
|
|
- * @return 解密后字符串
|
|
|
- */
|
|
|
- public static String encryptByDESede(String data, byte[] password) {
|
|
|
- //if (password.length!=24) {
|
|
|
- // throw new IllegalArgumentException("DESede需要传入秘钥信息");
|
|
|
- //}
|
|
|
-
|
|
|
- return SecureUtil.desede(password).encryptHex(data, StandardCharsets.UTF_8);
|
|
|
+ public static byte[] hex(String key) {
|
|
|
+ String f = DigestUtils.md5Hex(key);
|
|
|
+ int enkLength = 24;
|
|
|
+ byte[] bKeys = f.getBytes();
|
|
|
+ byte[] enk = new byte[enkLength];
|
|
|
+ System.arraycopy(bKeys, 0, enk, 0, enkLength);
|
|
|
+ return enk;
|
|
|
+// return new byte[1];
|
|
|
}
|
|
|
-
|
|
|
}
|