liguosong 4 years ago
parent
commit
c89586517b

+ 72 - 0
abi-cloud-qr-platform-server/src/test/java/com/abi/qms/platform/Test.java

@@ -0,0 +1,72 @@
+package com.abi.qms.platform;
+
+import cn.hutool.crypto.SecureUtil;
+import cn.hutool.crypto.symmetric.AES;
+import sun.misc.BASE64Decoder;
+
+import java.io.*;
+
+public class Test {
+
+        static String secretKey = "sXRnMPO9dXWkFNKY9GMv3g==";
+        static final BASE64Decoder decoder = new BASE64Decoder();
+
+        public static void main(String[] args) throws IOException {
+        String secretKey = "sXRnMPO9dXWkFNKY9GMv3g==";
+        System.out.println(secretKey+"开始");
+        String sp_jia = "D:\\test\\test+\\100w.txt";//原始文件
+        String sp = "D:\\test\\100w.txt";//原始文件
+        String sp_jie = "D:\\test\\test-\\100w.txt";//原始文件
+        String readToString=readToString(sp);//读取文件
+//       System.out.println(readToString);
+        getFile(jiami(readToString),sp_jia);//写入加密文件夹
+
+        String readToString_jia=readToString(sp_jia);//读取文件
+        getFile(jiemi(readToString_jia),sp_jie);//写入加密文件夹
+        System.out.println("完毕");
+    }
+
+        public static String jiami(String content) throws IOException {
+        AES aes = SecureUtil.aes(decoder.decodeBuffer(secretKey));
+        String encryptHex = aes.encryptHex(content);
+        return encryptHex;
+    }
+        public static String jiemi(String content) throws IOException {
+        AES aes = SecureUtil.aes(decoder.decodeBuffer(secretKey));
+        String decryptStr = aes.decryptStr(content);
+        return decryptStr;
+    }
+
+        public static void getFile(String name,String path) throws IOException {
+        // 打开一个写文件器,构造函数中的第二个参数true表示以追加形式写文件
+        Writer writer = new FileWriter(path, true);
+        BufferedWriter bufw = new BufferedWriter(writer);
+        bufw.write(name);
+        bufw.newLine();
+        bufw.flush();
+    }
+
+        public static String readToString(String fileName) {
+        String encoding = "UTF-8";
+        File file = new File(fileName);
+        Long filelength = file.length();
+        byte[] filecontent = new byte[filelength.intValue()];
+        try {
+            FileInputStream in = new FileInputStream(file);
+            in.read(filecontent);
+            in.close();
+        } catch (FileNotFoundException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        try {
+            return new String(filecontent, encoding);
+        } catch (UnsupportedEncodingException e) {
+            System.err.println("The OS does not support " + encoding);
+            e.printStackTrace();
+            return null;
+        }
+    }
+}
+