deason 3 éve
commit
52a8ff24e4

+ 33 - 0
.gitignore

@@ -0,0 +1,33 @@
+HELP.md
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/

+ 80 - 0
pom.xml

@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>cn.com.qmth.examcloud.devops</groupId>
+    <artifactId>dengbao-tool</artifactId>
+    <packaging>jar</packaging>
+    <version>1.0.0</version>
+
+    <parent>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-starter-parent</artifactId>
+        <version>2.3.12.RELEASE</version>
+    </parent>
+
+    <properties>
+        <java.version>1.8</java.version>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+            <version>3.12.0</version>
+        </dependency>
+        <dependency>
+            <groupId>commons-codec</groupId>
+            <artifactId>commons-codec</artifactId>
+            <version>1.15</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <configuration>
+                    <testFailureIgnore>true</testFailureIgnore>
+                    <skipTests>true</skipTests>
+                    <skip>true</skip>
+                </configuration>
+            </plugin>
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>${java.version}</source>
+                    <target>${java.version}</target>
+                    <encoding>${project.build.sourceEncoding}</encoding>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

+ 31 - 0
src/main/java/cn/com/qmth/examcloud/dengbao/DengBaoApplication.java

@@ -0,0 +1,31 @@
+package cn.com.qmth.examcloud.dengbao;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Bean;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+import java.util.concurrent.Executor;
+import java.util.concurrent.ThreadPoolExecutor;
+
+@EnableAsync
+@SpringBootApplication
+public class DengBaoApplication {
+
+    public static void main(String[] args) {
+        SpringApplication.run(DengBaoApplication.class, args);
+    }
+
+    @Bean
+    public Executor threadPoolTaskExecutor() {
+        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
+        executor.setThreadNamePrefix("DB-Task-");
+        executor.setCorePoolSize(5);
+        executor.setMaxPoolSize(10);
+        executor.initialize();
+        return executor;
+    }
+
+}

+ 35 - 0
src/main/java/cn/com/qmth/examcloud/dengbao/controller/IndexController.java

@@ -0,0 +1,35 @@
+package cn.com.qmth.examcloud.dengbao.controller;
+
+import cn.com.qmth.examcloud.dengbao.service.InitDataService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class IndexController {
+
+    @Autowired
+    private InitDataService initDataService;
+
+    @GetMapping(value = "/")
+    public String index() {
+        return "ok";
+    }
+
+    @GetMapping(value = "/init")
+    public String init() {
+        // 加密 或 解密
+        final boolean needEncrypt = true;
+
+        final String secretKey = "Qmth@87863577";
+
+        initDataService.init_EC_B_StudentCode(secretKey, needEncrypt);
+        // initDataService.init_EC_B_Student(secretKey, needEncrypt);
+        // initDataService.init_EC_E_ExamStudent(secretKey, needEncrypt);
+        // initDataService.init_EC_OE_ExamStudent(secretKey, needEncrypt);
+        // initDataService.init_EC_OE_ExamRecordData(secretKey, needEncrypt);
+
+        return "ok";
+    }
+
+}

+ 55 - 0
src/main/java/cn/com/qmth/examcloud/dengbao/model/EC_B_Student.java

@@ -0,0 +1,55 @@
+package cn.com.qmth.examcloud.dengbao.model;
+
+public class EC_B_Student {
+
+    private Long id;
+
+    private String identityNumber;
+
+    private String name;
+
+    private String phoneNumber;
+
+    private String securityPhone;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getIdentityNumber() {
+        return identityNumber;
+    }
+
+    public void setIdentityNumber(String identityNumber) {
+        this.identityNumber = identityNumber;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getPhoneNumber() {
+        return phoneNumber;
+    }
+
+    public void setPhoneNumber(String phoneNumber) {
+        this.phoneNumber = phoneNumber;
+    }
+
+    public String getSecurityPhone() {
+        return securityPhone;
+    }
+
+    public void setSecurityPhone(String securityPhone) {
+        this.securityPhone = securityPhone;
+    }
+
+}

+ 25 - 0
src/main/java/cn/com/qmth/examcloud/dengbao/model/EC_B_StudentCode.java

@@ -0,0 +1,25 @@
+package cn.com.qmth.examcloud.dengbao.model;
+
+public class EC_B_StudentCode {
+
+    private Long id;
+
+    private String identityNumber;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getIdentityNumber() {
+        return identityNumber;
+    }
+
+    public void setIdentityNumber(String identityNumber) {
+        this.identityNumber = identityNumber;
+    }
+
+}

+ 35 - 0
src/main/java/cn/com/qmth/examcloud/dengbao/model/EC_E_ExamStudent.java

@@ -0,0 +1,35 @@
+package cn.com.qmth.examcloud.dengbao.model;
+
+public class EC_E_ExamStudent {
+
+    private Long id;
+
+    private String identityNumber;
+
+    private String name;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getIdentityNumber() {
+        return identityNumber;
+    }
+
+    public void setIdentityNumber(String identityNumber) {
+        this.identityNumber = identityNumber;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+}

+ 35 - 0
src/main/java/cn/com/qmth/examcloud/dengbao/model/EC_OE_ExamRecordData.java

@@ -0,0 +1,35 @@
+package cn.com.qmth.examcloud.dengbao.model;
+
+public class EC_OE_ExamRecordData {
+
+    private Long id;
+
+    private String identityNumber;
+
+    private String studentName;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getIdentityNumber() {
+        return identityNumber;
+    }
+
+    public void setIdentityNumber(String identityNumber) {
+        this.identityNumber = identityNumber;
+    }
+
+    public String getStudentName() {
+        return studentName;
+    }
+
+    public void setStudentName(String studentName) {
+        this.studentName = studentName;
+    }
+
+}

+ 35 - 0
src/main/java/cn/com/qmth/examcloud/dengbao/model/EC_OE_ExamStudent.java

@@ -0,0 +1,35 @@
+package cn.com.qmth.examcloud.dengbao.model;
+
+public class EC_OE_ExamStudent {
+
+    private Long id;
+
+    private String identityNumber;
+
+    private String studentName;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getIdentityNumber() {
+        return identityNumber;
+    }
+
+    public void setIdentityNumber(String identityNumber) {
+        this.identityNumber = identityNumber;
+    }
+
+    public String getStudentName() {
+        return studentName;
+    }
+
+    public void setStudentName(String studentName) {
+        this.studentName = studentName;
+    }
+
+}

+ 329 - 0
src/main/java/cn/com/qmth/examcloud/dengbao/service/InitDataService.java

@@ -0,0 +1,329 @@
+package cn.com.qmth.examcloud.dengbao.service;
+
+import cn.com.qmth.examcloud.dengbao.model.*;
+import cn.com.qmth.examcloud.dengbao.utils.AESEncryptor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.BatchPreparedStatementSetter;
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.List;
+
+@Component
+public class InitDataService {
+
+    private static final Logger log = LoggerFactory.getLogger(InitDataService.class);
+
+    private static final int MAX_PAGE_SIZE = 10000;
+
+    private AESEncryptor aes = new AESEncryptor();
+
+    @Autowired
+    private JdbcTemplate jdbcTemplate;
+
+    @Async
+    public void init_EC_B_Student(String secretKey, boolean needEncrypt) {
+        StringBuilder querySql = new StringBuilder()
+                .append("select id,identity_number,name,phone_number,security_phone from ec_b_student ")
+                .append("where id > ?1 order by id asc limit 0,").append(MAX_PAGE_SIZE);
+
+        int total = 0;
+        Long startId = 0L;
+        while (true) {
+            List<EC_B_Student> list = jdbcTemplate.query(
+                    querySql.toString().replace("?1", startId.toString()),
+                    new BeanPropertyRowMapper(EC_B_Student.class)
+            );
+
+            if (CollectionUtils.isEmpty(list)) {
+                break;
+            }
+
+            total += list.size();
+            startId = list.get(list.size() - 1).getId();
+            log.info("[ec_b_student] lastId:{} curTotal:{}", startId, total);
+
+            for (EC_B_Student obj : list) {
+                if (needEncrypt) {
+                    obj.setIdentityNumber(aes.encrypt(secretKey, obj.getIdentityNumber()));
+                    obj.setName(aes.encrypt(secretKey, obj.getName()));
+                    obj.setPhoneNumber(aes.encrypt(secretKey, obj.getPhoneNumber()));
+                    obj.setSecurityPhone(aes.encrypt(secretKey, obj.getSecurityPhone()));
+                } else {
+                    obj.setIdentityNumber(aes.decrypt(secretKey, obj.getIdentityNumber()));
+                    obj.setName(aes.decrypt(secretKey, obj.getName()));
+                    obj.setPhoneNumber(aes.decrypt(secretKey, obj.getPhoneNumber()));
+                    obj.setSecurityPhone(aes.decrypt(secretKey, obj.getSecurityPhone()));
+                }
+            }
+
+            this.update_EC_B_Student(list);
+            list.clear();
+        }
+    }
+
+    private void update_EC_B_Student(List<EC_B_Student> list) {
+        StringBuilder sql = new StringBuilder()
+                .append("update ec_b_student ")
+                .append("set identity_number = ?,name = ?,phone_number = ?,security_phone = ? ")
+                .append("where id = ? ");
+
+        jdbcTemplate.batchUpdate(sql.toString(), new BatchPreparedStatementSetter() {
+            @Override
+            public void setValues(PreparedStatement ps, int n) throws SQLException {
+                EC_B_Student row = list.get(n);
+                ps.setString(1, row.getIdentityNumber());
+                ps.setString(2, row.getName());
+                ps.setString(3, row.getPhoneNumber());
+                ps.setString(4, row.getSecurityPhone());
+                ps.setLong(5, row.getId());
+            }
+
+            @Override
+            public int getBatchSize() {
+                return list.size();
+            }
+        });
+    }
+
+    @Async
+    public void init_EC_B_StudentCode(String secretKey, boolean needEncrypt) {
+        StringBuilder querySql = new StringBuilder()
+                .append("select id,identity_number from ec_b_student_code ")
+                .append("where id > ?1 order by id asc limit 0,").append(MAX_PAGE_SIZE);
+
+        int total = 0;
+        Long startId = 0L;
+        while (true) {
+            List<EC_B_StudentCode> list = jdbcTemplate.query(
+                    querySql.toString().replace("?1", startId.toString()),
+                    new BeanPropertyRowMapper(EC_B_StudentCode.class)
+            );
+
+            if (CollectionUtils.isEmpty(list)) {
+                break;
+            }
+
+            total += list.size();
+            startId = list.get(list.size() - 1).getId();
+            log.info("[ec_b_student_code] lastId:{} curTotal:{}", startId, total);
+
+            for (EC_B_StudentCode obj : list) {
+                if (needEncrypt) {
+                    obj.setIdentityNumber(aes.encrypt(secretKey, obj.getIdentityNumber()));
+                } else {
+                    obj.setIdentityNumber(aes.decrypt(secretKey, obj.getIdentityNumber()));
+                }
+            }
+
+            this.update_EC_B_StudentCode(list);
+            list.clear();
+        }
+    }
+
+    private void update_EC_B_StudentCode(List<EC_B_StudentCode> list) {
+        StringBuilder sql = new StringBuilder()
+                .append("update ec_b_student_code ")
+                .append("set identity_number = ? ")
+                .append("where id = ? ");
+
+        jdbcTemplate.batchUpdate(sql.toString(), new BatchPreparedStatementSetter() {
+            @Override
+            public void setValues(PreparedStatement ps, int n) throws SQLException {
+                EC_B_StudentCode row = list.get(n);
+                ps.setString(1, row.getIdentityNumber());
+                ps.setLong(2, row.getId());
+            }
+
+            @Override
+            public int getBatchSize() {
+                return list.size();
+            }
+        });
+    }
+
+    @Async
+    public void init_EC_E_ExamStudent(String secretKey, boolean needEncrypt) {
+        StringBuilder querySql = new StringBuilder()
+                .append("select id,identity_number,name from ec_e_exam_student ")
+                .append("where id > ?1 order by id asc limit 0,").append(MAX_PAGE_SIZE);
+
+        int total = 0;
+        Long startId = 0L;
+        while (true) {
+            List<EC_E_ExamStudent> list = jdbcTemplate.query(
+                    querySql.toString().replace("?1", startId.toString()),
+                    new BeanPropertyRowMapper(EC_E_ExamStudent.class)
+            );
+
+            if (CollectionUtils.isEmpty(list)) {
+                break;
+            }
+
+            total += list.size();
+            startId = list.get(list.size() - 1).getId();
+            log.info("[ec_e_exam_student] lastId:{} curTotal:{}", startId, total);
+
+            for (EC_E_ExamStudent obj : list) {
+                if (needEncrypt) {
+                    obj.setIdentityNumber(aes.encrypt(secretKey, obj.getIdentityNumber()));
+                    obj.setName(aes.encrypt(secretKey, obj.getName()));
+                } else {
+                    obj.setIdentityNumber(aes.decrypt(secretKey, obj.getIdentityNumber()));
+                    obj.setName(aes.decrypt(secretKey, obj.getName()));
+                }
+            }
+
+            this.update_EC_E_ExamStudent(list);
+            list.clear();
+        }
+    }
+
+    private void update_EC_E_ExamStudent(List<EC_E_ExamStudent> list) {
+        StringBuilder sql = new StringBuilder()
+                .append("update ec_e_exam_student ")
+                .append("set identity_number = ?,name = ? ")
+                .append("where id = ? ");
+
+        jdbcTemplate.batchUpdate(sql.toString(), new BatchPreparedStatementSetter() {
+            @Override
+            public void setValues(PreparedStatement ps, int n) throws SQLException {
+                EC_E_ExamStudent row = list.get(n);
+                ps.setString(1, row.getIdentityNumber());
+                ps.setString(2, row.getName());
+                ps.setLong(3, row.getId());
+            }
+
+            @Override
+            public int getBatchSize() {
+                return list.size();
+            }
+        });
+    }
+
+    @Async
+    public void init_EC_OE_ExamStudent(String secretKey, boolean needEncrypt) {
+        StringBuilder querySql = new StringBuilder()
+                .append("select id,identity_number,student_name from ec_oe_exam_student ")
+                .append("where id > ?1 order by id asc limit 0,").append(MAX_PAGE_SIZE);
+
+        int total = 0;
+        Long startId = 0L;
+        while (true) {
+            List<EC_OE_ExamStudent> list = jdbcTemplate.query(
+                    querySql.toString().replace("?1", startId.toString()),
+                    new BeanPropertyRowMapper(EC_OE_ExamStudent.class)
+            );
+
+            if (CollectionUtils.isEmpty(list)) {
+                break;
+            }
+
+            total += list.size();
+            startId = list.get(list.size() - 1).getId();
+            log.info("[ec_oe_exam_student] lastId:{} curTotal:{}", startId, total);
+
+            for (EC_OE_ExamStudent obj : list) {
+                if (needEncrypt) {
+                    obj.setIdentityNumber(aes.encrypt(secretKey, obj.getIdentityNumber()));
+                    obj.setStudentName(aes.encrypt(secretKey, obj.getStudentName()));
+                } else {
+                    obj.setIdentityNumber(aes.decrypt(secretKey, obj.getIdentityNumber()));
+                    obj.setStudentName(aes.decrypt(secretKey, obj.getStudentName()));
+                }
+            }
+
+            this.update_EC_OE_ExamStudent(list);
+            list.clear();
+        }
+    }
+
+    private void update_EC_OE_ExamStudent(List<EC_OE_ExamStudent> list) {
+        StringBuilder sql = new StringBuilder()
+                .append("update ec_oe_exam_student ")
+                .append("set identity_number = ?,student_name = ? ")
+                .append("where id = ? ");
+
+        jdbcTemplate.batchUpdate(sql.toString(), new BatchPreparedStatementSetter() {
+            @Override
+            public void setValues(PreparedStatement ps, int n) throws SQLException {
+                EC_OE_ExamStudent row = list.get(n);
+                ps.setString(1, row.getIdentityNumber());
+                ps.setString(2, row.getStudentName());
+                ps.setLong(3, row.getId());
+            }
+
+            @Override
+            public int getBatchSize() {
+                return list.size();
+            }
+        });
+    }
+
+    @Async
+    public void init_EC_OE_ExamRecordData(String secretKey, boolean needEncrypt) {
+        StringBuilder querySql = new StringBuilder()
+                .append("select id,identity_number,student_name from ec_oe_exam_record_data ")
+                .append("where id > ?1 order by id asc limit 0,").append(MAX_PAGE_SIZE);
+
+        int total = 0;
+        Long startId = 0L;
+        while (true) {
+            List<EC_OE_ExamRecordData> list = jdbcTemplate.query(
+                    querySql.toString().replace("?1", startId.toString()),
+                    new BeanPropertyRowMapper(EC_OE_ExamRecordData.class)
+            );
+
+            if (CollectionUtils.isEmpty(list)) {
+                break;
+            }
+
+            total += list.size();
+            startId = list.get(list.size() - 1).getId();
+            log.info("[ec_oe_exam_record_data] lastId:{} curTotal:{}", startId, total);
+
+            for (EC_OE_ExamRecordData obj : list) {
+                if (needEncrypt) {
+                    obj.setIdentityNumber(aes.encrypt(secretKey, obj.getIdentityNumber()));
+                    obj.setStudentName(aes.encrypt(secretKey, obj.getStudentName()));
+                } else {
+                    obj.setIdentityNumber(aes.decrypt(secretKey, obj.getIdentityNumber()));
+                    obj.setStudentName(aes.decrypt(secretKey, obj.getStudentName()));
+                }
+            }
+
+            this.update_EC_OE_ExamRecordData(list);
+            list.clear();
+        }
+    }
+
+    private void update_EC_OE_ExamRecordData(List<EC_OE_ExamRecordData> list) {
+        StringBuilder sql = new StringBuilder()
+                .append("update ec_oe_exam_record_data ")
+                .append("set identity_number = ?,student_name = ? ")
+                .append("where id = ? ");
+
+        jdbcTemplate.batchUpdate(sql.toString(), new BatchPreparedStatementSetter() {
+            @Override
+            public void setValues(PreparedStatement ps, int n) throws SQLException {
+                EC_OE_ExamRecordData row = list.get(n);
+                ps.setString(1, row.getIdentityNumber());
+                ps.setString(2, row.getStudentName());
+                ps.setLong(3, row.getId());
+            }
+
+            @Override
+            public int getBatchSize() {
+                return list.size();
+            }
+        });
+    }
+
+}

+ 64 - 0
src/main/java/cn/com/qmth/examcloud/dengbao/utils/AESEncryptor.java

@@ -0,0 +1,64 @@
+package cn.com.qmth.examcloud.dengbao.utils;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.codec.binary.StringUtils;
+import org.apache.commons.codec.digest.DigestUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.crypto.Cipher;
+import javax.crypto.NoSuchPaddingException;
+import javax.crypto.spec.SecretKeySpec;
+import java.nio.charset.StandardCharsets;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.util.Arrays;
+
+public class AESEncryptor {
+
+    private static final Logger log = LoggerFactory.getLogger(AESEncryptor.class);
+
+    private static final String AES = "AES";
+
+    public String encrypt(String key, final Object plaintext) {
+        if (null == plaintext) {
+            return null;
+        }
+
+        try {
+            byte[] data = StringUtils.getBytesUtf8(String.valueOf(plaintext));
+            byte[] result = getCipher(key, Cipher.ENCRYPT_MODE).doFinal(data);
+            return Base64.encodeBase64String(result);
+        } catch (Exception e) {
+            log.error(e.getMessage());
+            throw new RuntimeException(e);
+        }
+    }
+
+    public String decrypt(String key, final String ciphertext) {
+        if (null == ciphertext) {
+            return null;
+        }
+
+        try {
+            byte[] data = Base64.decodeBase64(ciphertext);
+            byte[] result = getCipher(key, Cipher.DECRYPT_MODE).doFinal(data);
+            return new String(result, StandardCharsets.UTF_8);
+        } catch (Exception e) {
+            log.error(e.getMessage());
+            throw new RuntimeException("Decrypt fail, maybe secretKey is wrong...", e);
+        }
+    }
+
+    private Cipher getCipher(String key, final int decryptMode)
+            throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException {
+        Cipher result = Cipher.getInstance(AES);
+        result.init(decryptMode, new SecretKeySpec(createSecretKey(key), AES));
+        return result;
+    }
+
+    private byte[] createSecretKey(String key) {
+        return Arrays.copyOf(DigestUtils.sha1(key), 16);
+    }
+
+}

+ 15 - 0
src/main/resources/application.properties

@@ -0,0 +1,15 @@
+server.port=8080
+server.servlet.context-path=/
+# mysql config
+mysql.host=192.168.0.54:3306
+mysql.database=examcloud_dengbao
+spring.datasource.username=examcloud_dengbao
+spring.datasource.password=examcloud_dengbao_123
+spring.datasource.url=jdbc:mysql://${mysql.host}/${mysql.database}?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=GMT%2b8&rewriteBatchedStatements=true
+spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
+spring.jpa.hibernate.ddl-auto=validate
+# logger config
+logging.level.org.apache=warn
+logging.level.org.springframework=warn
+#logging.level.org.springframework.jdbc.core.JdbcTemplate=debug
+logging.level.cn.com.qmth=info

+ 20 - 0
src/test/java/cn/com/qmth/examcloud/dengbao/test/DengBaoTest.java

@@ -0,0 +1,20 @@
+package cn.com.qmth.examcloud.dengbao.test;
+
+import cn.com.qmth.examcloud.dengbao.utils.AESEncryptor;
+import org.junit.jupiter.api.Test;
+
+// @SpringBootTest
+public class DengBaoTest {
+
+    @Test
+    public void initTest() {
+        final String secretKey = "Qmth@87863577";
+
+        AESEncryptor aes = new AESEncryptor();
+        String encryptStr = aes.encrypt(secretKey, "xxx");
+        System.out.println(encryptStr);
+
+        System.out.println(aes.decrypt(secretKey, encryptStr));
+    }
+
+}