|
@@ -0,0 +1,111 @@
|
|
|
+package com.fdkankan.scene.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
+import com.fdkankan.common.constant.ErrorCode;
|
|
|
+import com.fdkankan.common.exception.BusinessException;
|
|
|
+import com.fdkankan.common.util.DateExtUtil;
|
|
|
+import com.fdkankan.scene.service.IJmgaService;
|
|
|
+import com.fdkankan.scene.vo.SceneInfoParamVO;
|
|
|
+import com.fdkankan.web.util.WebUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.cloud.context.config.annotation.RefreshScope;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.crypto.BadPaddingException;
|
|
|
+import javax.crypto.Cipher;
|
|
|
+import javax.crypto.IllegalBlockSizeException;
|
|
|
+import javax.crypto.NoSuchPaddingException;
|
|
|
+import javax.crypto.spec.SecretKeySpec;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.security.InvalidKeyException;
|
|
|
+import java.security.NoSuchAlgorithmException;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@RefreshScope
|
|
|
+@Service
|
|
|
+public class JmgaServiceImpl implements IJmgaService {
|
|
|
+
|
|
|
+ @Value("${scene.view.encrypt-key:3d8904474ebbdbbd81c5952524dad646}")
|
|
|
+ private String ENCRYPT_KEY;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> checkSceneViewGign(SceneInfoParamVO param, HttpServletRequest request) throws Exception{
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ String sign = param.getSign();
|
|
|
+ if(StrUtil.isEmpty(sign)){
|
|
|
+ result.put("flag", true);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ String userName = null, ip = null, timestamp = null;
|
|
|
+ result.put("flag", false);
|
|
|
+ String[] split = null;
|
|
|
+ try {byte[] raw = ENCRYPT_KEY.getBytes(StandardCharsets.UTF_8);
|
|
|
+ Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
|
|
|
+ SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
|
|
|
+ cipher.init(Cipher.DECRYPT_MODE, skeySpec);
|
|
|
+ byte[] encrypted1 = Base64.getDecoder().decode(sign);
|
|
|
+ byte[] original = cipher.doFinal(encrypted1);
|
|
|
+
|
|
|
+ //字节转换字符串
|
|
|
+ String decode = new String(original, StandardCharsets.UTF_8);
|
|
|
+ split = decode.split("@");
|
|
|
+
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("签名解密失败", e);
|
|
|
+ throw new BusinessException(ErrorCode.AUTH_FAIL.code(), "签名解密失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(split.length == 1){
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0; i < split.length; i++){
|
|
|
+ if(i == 0){
|
|
|
+ userName = split[i];
|
|
|
+ }
|
|
|
+ if(i == 1){
|
|
|
+ ip = split[i];
|
|
|
+ }
|
|
|
+ if(i == 2){
|
|
|
+ timestamp = split[i];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ result.put("userName", userName);
|
|
|
+
|
|
|
+ String ipAddress = WebUtil.getIpAddress(request);
|
|
|
+ if(StrUtil.isNotEmpty(ip) && !ip.equals(ipAddress)){
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StrUtil.isNotEmpty(timestamp) && Calendar.getInstance().getTime().after(new Date(Long.valueOf(timestamp) * 1000))){
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ result.put("flag", true);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) throws NoSuchPaddingException, NoSuchAlgorithmException, BadPaddingException, IllegalBlockSizeException, InvalidKeyException {
|
|
|
+
|
|
|
+ String sign = "P9md4QmKxb4VvpUY1pSnG3ycLyJ7c95mloXRrp50m+J6lhs0WHHD5rtPTSI8TXKC";
|
|
|
+ String ENCRYPT_KEY = "3d8904474ebbdbbd81c5952524dad646";
|
|
|
+ byte[] raw = ENCRYPT_KEY.getBytes(StandardCharsets.UTF_8);
|
|
|
+ Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
|
|
|
+ SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
|
|
|
+ cipher.init(Cipher.DECRYPT_MODE, skeySpec);
|
|
|
+ byte[] encrypted1 = Base64.getDecoder().decode(sign);
|
|
|
+ byte[] original = cipher.doFinal(encrypted1);
|
|
|
+
|
|
|
+ //字节转换字符串
|
|
|
+ String decode = new String(original, StandardCharsets.UTF_8);
|
|
|
+ System.out.println(decode);
|
|
|
+ String[] split = decode.split("@");
|
|
|
+ int length = split.length;
|
|
|
+
|
|
|
+ }
|
|
|
+}
|