代码优化

This commit is contained in:
thinkgem
2023-06-09 19:58:46 +08:00
parent 8361910b16
commit a84d5168ec

View File

@@ -4,11 +4,11 @@
*/ */
package com.jeesite.common.codec; package com.jeesite.common.codec;
import com.jeesite.common.lang.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.jeesite.common.lang.StringUtils;
/** /**
* DES加密解密工具 * DES加密解密工具
* 加密DesUtils.encode("admin","1,2,3"); * 加密DesUtils.encode("admin","1,2,3");
@@ -17,23 +17,23 @@ import com.jeesite.common.lang.StringUtils;
*/ */
public class DesUtils { public class DesUtils {
private static DesCore desCore = new DesCore(); private static final DesCore desCore = new DesCore();
/** /**
* DES加密secretKey代表3个key用逗号分隔 * DES加密secretKey代表3个key用逗号分隔
*/ */
public static String encode(String data, String secretKey) { public static String encode(String data, String secretKey) {
if (StringUtils.isBlank(data)){ if (StringUtils.isBlank(data)){
return ""; return StringUtils.EMPTY;
} }
if ("Base64".equals(secretKey)) { if ("Base64".equalsIgnoreCase(secretKey)) {
return EncodeUtils.encodeBase64(data); return EncodeUtils.encodeBase64(data);
} }
String[] ks = StringUtils.split(secretKey, ","); String[] ks = StringUtils.split(secretKey, StringUtils.COMMA);
if (ks.length >= 3){ if (ks.length >= 3){
return desCore.strEnc(data, ks[0], ks[1], ks[2]); return desCore.strEnc(data, ks[0], ks[1], ks[2]);
} }
return desCore.strEnc(data, secretKey, "", ""); return desCore.strEnc(data, secretKey, StringUtils.EMPTY, StringUtils.EMPTY);
} }
/** /**
@@ -43,18 +43,18 @@ public class DesUtils {
if (StringUtils.isBlank(data)){ if (StringUtils.isBlank(data)){
return ""; return "";
} }
if ("Base64".equals(secretKey)) { if ("Base64".equalsIgnoreCase(secretKey)) {
try { try {
return EncodeUtils.decodeBase64String(data); return EncodeUtils.decodeBase64String(data);
}catch (IllegalArgumentException e) { }catch (IllegalArgumentException e) {
return ""; return StringUtils.EMPTY;
} }
} }
String[] ks = StringUtils.split(secretKey, ","); String[] ks = StringUtils.split(secretKey, StringUtils.COMMA);
if (ks.length >= 3){ if (ks.length >= 3){
return desCore.strDec(data, ks[0], ks[1], ks[2]); return desCore.strDec(data, ks[0], ks[1], ks[2]);
} }
return desCore.strDec(data, secretKey, "", ""); return desCore.strDec(data, secretKey, StringUtils.EMPTY, StringUtils.EMPTY);
} }
/** /**
@@ -69,7 +69,6 @@ public class DesUtils {
* encrypt the string to string made up of hex return the encrypted string * encrypt the string to string made up of hex return the encrypted string
*/ */
public String strEnc(String data, String firstKey, String secondKey, String thirdKey) { public String strEnc(String data, String firstKey, String secondKey, String thirdKey) {
int leng = data.length(); int leng = data.length();
String encData = ""; String encData = "";
List firstKeyBt = null, secondKeyBt = null, thirdKeyBt = null; List firstKeyBt = null, secondKeyBt = null, thirdKeyBt = null;