dsx 1 year ago
parent
commit
9c1a7eea5a

+ 1 - 0
4dkankan-common-utils/src/main/java/com/fdkankan/common/constant/ErrorCode.java

@@ -23,6 +23,7 @@ public enum ErrorCode {
     MISSING_REQUIRED_PARAMETERS(4007,"缺少必要参数"),
     USER_NOT_LOGIN(4008, "用户未登录"),
     NOT_RECORD(4009, "暂无记录"),
+    USERNAME_PASSWORD_REQUIRE(4010, "账号密码不能为空"),
     ERROR_MSG(40010, "操作失败"),
     EMPTY_FILE(40011, "空文件"),
     AGENT_EXIST(40012, "经销商已存在"),

+ 71 - 20
4dkankan-common-utils/src/main/java/com/fdkankan/common/util/AesUtil.java

@@ -1,12 +1,16 @@
 package com.fdkankan.common.util;
 
-import com.aliyuncs.utils.Base64Helper;
+import org.apache.commons.codec.binary.Base64;
 
 import javax.crypto.Cipher;
 import javax.crypto.spec.IvParameterSpec;
 import javax.crypto.spec.SecretKeySpec;
+import java.nio.charset.StandardCharsets;
 
 public class AesUtil {
+
+    public static final String ALMODE_CBC_NOPADDING = "AES/CBC/NoPadding";
+
     /**
      * @author miracle.qu
      * AES算法加密明文
@@ -16,30 +20,77 @@ public class AesUtil {
      * @return 密文
      */
     public static String encryptAES(String data,String key,String iv) throws Exception {
-        try {
-            Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
-            int blockSize = cipher.getBlockSize();
-            byte[] dataBytes = data.getBytes();
-            int plaintextLength = dataBytes.length;
+        return encryptCBC(data,key,iv,ALMODE_CBC_NOPADDING);
+    }
 
-            if (plaintextLength % blockSize != 0) {
-                plaintextLength = plaintextLength + (blockSize - (plaintextLength % blockSize));
-            }
+    public static String encryptCBC(String data,String key,String iv,String alMode) throws Exception {
+        Cipher cipher = Cipher.getInstance(alMode);
+        int blockSize = cipher.getBlockSize();
+        byte[] dataBytes = data.getBytes();
+        int plaintextLength = dataBytes.length;
 
-            byte[] plaintext = new byte[plaintextLength];
-            System.arraycopy(dataBytes, 0, plaintext, 0, dataBytes.length);
+        if (plaintextLength % blockSize != 0) {
+            plaintextLength = plaintextLength + (blockSize - (plaintextLength % blockSize));
+        }
 
-            SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES");
-            IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes());
+        byte[] plaintext = new byte[plaintextLength];
+        System.arraycopy(dataBytes, 0, plaintext, 0, dataBytes.length);
 
-            cipher.init(Cipher.ENCRYPT_MODE, keyspec, ivspec);
-            byte[] encrypted = cipher.doFinal(plaintext);
+        SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES");
+        IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes());
 
-            return Base64Helper.encode(encrypted).trim();
+        cipher.init(Cipher.ENCRYPT_MODE, keyspec, ivspec);
+        byte[] encrypted = cipher.doFinal(plaintext);
 
-        } catch (Exception e) {
-            e.printStackTrace();
-            return null;
-        }
+        return new Base64().encodeToString(encrypted).trim();
+    }
+
+    public static String decryptCBC(String data, String key, String iv, String alMode) throws Exception {
+        byte[] encrypted1 = new Base64().decode(data);
+
+        Cipher cipher = Cipher.getInstance(alMode);
+        SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES");
+        IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes());
+
+        cipher.init(Cipher.DECRYPT_MODE, keyspec, ivspec); //使用密钥初始化,设置为解密模式
+
+        byte[] original = cipher.doFinal(encrypted1);	//执行操作
+        String originalString = new String(original);
+        return originalString.trim();
+    }
+
+    public static String encryptECB(String data,String key,String alMode) throws Exception {
+        byte[] raw = key.getBytes(StandardCharsets.UTF_8);
+        SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
+        Cipher cipher = Cipher.getInstance(alMode);
+        cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
+        byte[] byteEncode = data.getBytes(StandardCharsets.UTF_8);
+        byte[] byteAes = cipher.doFinal(byteEncode, 0, byteEncode.length);
+
+        return java.util.Base64.getEncoder().encodeToString(byteAes);
+    }
+
+    public static String decryptECB(String data,String key,String alMode) throws Exception {
+        byte[] raw = key.getBytes(StandardCharsets.UTF_8);
+        Cipher cipher = Cipher.getInstance(alMode);
+        SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
+        cipher.init(Cipher.DECRYPT_MODE, skeySpec);
+        byte[] encrypted1 = java.util.Base64.getDecoder().decode(data);
+        byte[] original = cipher.doFinal(encrypted1);
+
+        //字节转换字符串
+        return new String(original, StandardCharsets.UTF_8).trim();
     }
+
+    public static void main(String[] args) throws Exception {
+//        final String encode = cn.hutool.core.codec.Base64.encode("Aa1234567".getBytes());
+//        System.out.println(encode);
+
+        String data = "linjunbo@192.168.0.30@1695872675";
+        String s = encryptECB(data, "3d8904474ebbdbbd81c5952524dad646", "AES/ECB/PKCS5Padding");
+        System.out.println(s);
+    }
+
+
+
 }

+ 18 - 0
4dkankan-common-web/pom.xml

@@ -38,6 +38,12 @@
     <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-webflux</artifactId>
+      <exclusions>
+        <exclusion>
+          <groupId>org.springframework</groupId>
+          <artifactId>spring-web</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
 
     <dependency>
@@ -81,6 +87,18 @@
     <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-web</artifactId>
+      <exclusions>
+        <exclusion>
+          <groupId>org.springframework</groupId>
+          <artifactId>spring-web</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-web</artifactId>
+      <version>5.2.16.RELEASE</version>
     </dependency>
 
     <dependency>

+ 1 - 1
4dkankan-common-web/src/main/java/com/fdkankan/web/util/WebUtil.java

@@ -52,7 +52,7 @@ public class WebUtil {
                 return ip;
             }
         }
-            ip = request.getHeader("Proxy-Client-IP");
+        ip = request.getHeader("Proxy-Client-IP");
         if(StrUtil.isNotBlank(ip)) return ip;
             ip = request.getHeader("WL-Proxy-Client-IP");
         if(StrUtil.isNotBlank(ip)) return ip;

+ 8 - 1
4dkankan-utils-fyun-local/src/main/java/com/fdkankan/fyun/local/LocalFileService.java

@@ -208,6 +208,13 @@ public class LocalFileService extends AbstractFYunFileService {
 
     @Override
     public Long getSpace(String bucket, String key) {
-        return null;
+        String ossPath = getOssPath(bucket, key);
+        if(!FileUtil.exist(ossPath)){
+            return 0L;
+        }
+        if(FileUtil.isFile(ossPath)){
+            return FileUtil.size(new File(ossPath));
+        }
+        return FileUtil.loopFiles(ossPath).stream().mapToLong(File::length).sum();
     }
 }