🐛 修复在JDK 17的环境下无sun相关的包
1. 使用hutool替换sun 2. 删除未使用的包导入
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
package com.zbkj.common.interceptor;
|
package com.zbkj.common.interceptor;
|
||||||
|
|
||||||
|
import cn.hutool.core.codec.Base64;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||||
import org.springframework.core.io.support.ResourcePatternResolver;
|
import org.springframework.core.io.support.ResourcePatternResolver;
|
||||||
import org.springframework.util.AntPathMatcher;
|
import org.springframework.util.AntPathMatcher;
|
||||||
import org.springframework.util.FileCopyUtils;
|
import org.springframework.util.FileCopyUtils;
|
||||||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
||||||
import sun.misc.BASE64Decoder;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
@@ -52,7 +52,7 @@ public class SwaggerInterceptor extends HandlerInterceptorAdapter {
|
|||||||
public boolean httpBasicAuth(String authorization) throws IOException {
|
public boolean httpBasicAuth(String authorization) throws IOException {
|
||||||
if(check){
|
if(check){
|
||||||
if (authorization != null && authorization.split(" ").length == 2) {
|
if (authorization != null && authorization.split(" ").length == 2) {
|
||||||
String userAndPass = new String(new BASE64Decoder().decodeBuffer(authorization.split(" ")[1]));
|
String userAndPass = Base64.decodeStr(authorization.split(" ")[1]);
|
||||||
String username = userAndPass.split(":").length == 2 ? userAndPass.split(":")[0] : null;
|
String username = userAndPass.split(":").length == 2 ? userAndPass.split(":")[0] : null;
|
||||||
String password = userAndPass.split(":").length == 2 ? userAndPass.split(":")[1] : null;
|
String password = userAndPass.split(":").length == 2 ? userAndPass.split(":")[1] : null;
|
||||||
return this.username.equals(username) && this.password.equals(password);
|
return this.username.equals(username) && this.password.equals(password);
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.zbkj.common.request;
|
package com.zbkj.common.request;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.sun.org.apache.xpath.internal.operations.Bool;
|
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -9,11 +8,8 @@ import lombok.EqualsAndHashCode;
|
|||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
import org.hibernate.validator.constraints.Range;
|
import org.hibernate.validator.constraints.Range;
|
||||||
|
|
||||||
import javax.validation.constraints.Max;
|
|
||||||
import javax.validation.constraints.Min;
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品表
|
* 商品表
|
||||||
|
|||||||
@@ -1,23 +1,19 @@
|
|||||||
package com.zbkj.common.utils;
|
package com.zbkj.common.utils;
|
||||||
|
|
||||||
|
import cn.hutool.core.codec.Base64;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.crypto.SecureUtil;
|
import cn.hutool.crypto.SecureUtil;
|
||||||
|
import cn.hutool.crypto.symmetric.DES;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.zbkj.common.constants.Constants;
|
import com.zbkj.common.constants.Constants;
|
||||||
import com.zbkj.common.exception.CrmebException;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import javax.crypto.Cipher;
|
|
||||||
import javax.crypto.SecretKey;
|
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.Key;
|
|
||||||
import java.security.Security;
|
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
@@ -37,43 +33,26 @@ import java.util.regex.Pattern;
|
|||||||
*/
|
*/
|
||||||
public class CrmebUtil {
|
public class CrmebUtil {
|
||||||
|
|
||||||
public static String encryptPassword(String pwd, String key){
|
public static String encryptPassword(String pwd, String key) {
|
||||||
try {
|
DES des = new DES(getDESSercretKey(key));
|
||||||
Security.addProvider(new com.sun.crypto.provider.SunJCE());
|
byte[] result = des.encrypt(pwd);
|
||||||
Key _key = getDESSercretKey(key);
|
return Base64.encode(result);
|
||||||
Cipher cipher = Cipher.getInstance("DES");
|
|
||||||
cipher.init(Cipher.ENCRYPT_MODE, _key);
|
|
||||||
byte[] data = pwd.getBytes(StandardCharsets.UTF_8);
|
|
||||||
byte[] result = cipher.doFinal(data);
|
|
||||||
return new sun.misc.BASE64Encoder().encode(result);
|
|
||||||
}catch (Exception e){
|
|
||||||
throw new CrmebException("密码处理异常");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解密密码
|
* 解密密码
|
||||||
*/
|
*/
|
||||||
public static String decryptPassowrd(String pwd, String key)
|
public static String decryptPassowrd(String pwd, String key) {
|
||||||
throws Exception {
|
DES des = new DES(getDESSercretKey(key));
|
||||||
Security.addProvider(new com.sun.crypto.provider.SunJCE());
|
return des.decryptStr(pwd);
|
||||||
Key aKey = getDESSercretKey(key);
|
|
||||||
Cipher cipher = Cipher.getInstance("DES");
|
|
||||||
cipher.init(Cipher.DECRYPT_MODE, aKey);
|
|
||||||
|
|
||||||
byte[] data = new sun.misc.BASE64Decoder().decodeBuffer(pwd);
|
|
||||||
byte[] result = cipher.doFinal(data);
|
|
||||||
|
|
||||||
return new String(result, StandardCharsets.UTF_8);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得DES加密秘钥
|
* 获得DES加密秘钥
|
||||||
* @param key
|
* @param key
|
||||||
* @return
|
* @return
|
||||||
* @throws UnsupportedEncodingException
|
|
||||||
*/
|
*/
|
||||||
public static SecretKey getDESSercretKey(String key) throws UnsupportedEncodingException {
|
public static byte[] getDESSercretKey(String key) {
|
||||||
byte[] result = new byte[8];
|
byte[] result = new byte[8];
|
||||||
byte[] keys = null;
|
byte[] keys = null;
|
||||||
keys = key.getBytes(StandardCharsets.UTF_8);
|
keys = key.getBytes(StandardCharsets.UTF_8);
|
||||||
@@ -84,7 +63,7 @@ public class CrmebUtil {
|
|||||||
result[i] = 0x01;
|
result[i] = 0x01;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new SecretKeySpec(result, "DES");
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -135,7 +114,19 @@ public class CrmebUtil {
|
|||||||
*/
|
*/
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
// System.out.println(encryptPassword("123456", "admin"));
|
// System.out.println(encryptPassword("123456", "admin"));
|
||||||
System.out.println(decryptPassowrd("", ""));
|
// System.out.println(decryptPassowrd("", ""));
|
||||||
|
|
||||||
|
String key = "123456";
|
||||||
|
String data = "中国123ABCabc";
|
||||||
|
System.out.println("原始数据:" + data);
|
||||||
|
String encryptPassword = encryptPassword(data, key);
|
||||||
|
System.out.println("加密结果:" + encryptPassword);
|
||||||
|
String decryptPassowrd = decryptPassowrd(encryptPassword, key);
|
||||||
|
System.out.println("解密结果:" + decryptPassowrd);
|
||||||
|
// 执行结果如下:
|
||||||
|
// 原始数据:中国123ABCabc
|
||||||
|
// 加密结果:5JNGj04iE/XUuTZM75zMrA==
|
||||||
|
// 解密结果:中国123ABCabc
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user