xiongzhu 4 vuotta sitten
vanhempi
commit
147c1487a4

+ 14 - 1
src/main/data-center-admin/src/plugins/http.js

@@ -25,6 +25,15 @@ function decrypt(content) {
     return decrypted.toString(CryptoJS.enc.Utf8);
 }
 
+function encrypt(content) {
+    const key = CryptoJS.enc.Hex.parse('2181E9E80460B852859EE455AC5203D9');
+    var encrypted = CryptoJS.AES.encrypt(content, key, {
+        mode: CryptoJS.mode.ECB,
+        padding: CryptoJS.pad.Pkcs7
+    });
+    return encrypted.ciphertext.toString(CryptoJS.enc.Hex);
+}
+
 axiosInstance.interceptors.request.use(
     function(config) {
         config.headers = config.headers || {};
@@ -107,9 +116,13 @@ export default {
             },
             post(url, body, options) {
                 options = options || {};
+                options.headers = options.headers || {};
                 body = body || {};
                 if (!(body instanceof FormData)) {
-                    if (options.body !== 'json') {
+                    if (options.body === 'json') {
+                        body = encrypt(JSON.stringify(body));
+                        options.headers['content-type'] = 'application/json';
+                    } else {
                         body = qs.stringify(body);
                     }
                 }

+ 14 - 1
src/main/data-center/src/plugins/http.js

@@ -24,6 +24,15 @@ function decrypt(content) {
     return decrypted.toString(CryptoJS.enc.Utf8);
 }
 
+function encrypt(content) {
+    const key = CryptoJS.enc.Hex.parse('2181E9E80460B852859EE455AC5203D9');
+    var encrypted = CryptoJS.AES.encrypt(content, key, {
+        mode: CryptoJS.mode.ECB,
+        padding: CryptoJS.pad.Pkcs7
+    });
+    return encrypted.ciphertext.toString(CryptoJS.enc.Hex);
+}
+
 axiosInstance.interceptors.request.use(
     function (config) {
         config.headers = config.headers || {};
@@ -94,9 +103,13 @@ export default {
             },
             post(url, body, options) {
                 options = options || {};
+                options.headers = options.headers || {};
                 body = body || {};
                 if (!(body instanceof FormData)) {
-                    if (options.body !== 'json') {
+                    if (options.body === 'json') {
+                        body = encrypt(JSON.stringify(body));
+                        options.headers['content-type'] = 'application/json';
+                    } else {
                         body = qs.stringify(body);
                     }
                 }

+ 85 - 63
src/main/java/cn/licoy/encryptbody/advice/DecryptRequestBodyAdvice.java

@@ -4,6 +4,7 @@ import cn.licoy.encryptbody.annotation.decrypt.AESDecryptBody;
 import cn.licoy.encryptbody.annotation.decrypt.DESDecryptBody;
 import cn.licoy.encryptbody.annotation.decrypt.DecryptBody;
 import cn.licoy.encryptbody.annotation.decrypt.RSADecryptBody;
+import cn.licoy.encryptbody.annotation.encrypt.*;
 import cn.licoy.encryptbody.bean.DecryptAnnotationInfoBean;
 import cn.licoy.encryptbody.bean.DecryptHttpInputMessage;
 import cn.licoy.encryptbody.config.EncryptBodyConfig;
@@ -14,6 +15,7 @@ import cn.licoy.encryptbody.util.AESEncryptUtil;
 import cn.licoy.encryptbody.util.CheckUtils;
 import cn.licoy.encryptbody.util.DESEncryptUtil;
 import cn.licoy.encryptbody.util.StringUtils;
+import jodd.util.ReflectUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.io.IOUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -22,20 +24,26 @@ import org.springframework.core.annotation.Order;
 import org.springframework.http.HttpInputMessage;
 import org.springframework.http.converter.HttpMessageConverter;
 import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdvice;
 
+import javax.annotation.Nonnull;
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
 
 /**
  * 请求数据的加密信息解密处理<br>
- *     本类只对控制器参数中含有<strong>{@link org.springframework.web.bind.annotation.RequestBody}</strong>
- *     以及package为<strong><code>cn.licoy.encryptbody.annotation.decrypt</code></strong>下的注解有效
- * @see RequestBodyAdvice
+ * 本类只对控制器参数中含有<strong>{@link org.springframework.web.bind.annotation.RequestBody}</strong>
+ * 以及package为<strong><code>cn.licoy.encryptbody.annotation.decrypt</code></strong>下的注解有效
+ *
  * @author licoy.cn
  * @version 2018/9/7
+ * @see RequestBodyAdvice
  */
 @Order(1)
 @ControllerAdvice
@@ -46,65 +54,77 @@ public class DecryptRequestBodyAdvice implements RequestBodyAdvice {
     private EncryptBodyConfig config;
 
     @Override
-    public boolean supports(MethodParameter methodParameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) {
+    public boolean supports(MethodParameter methodParameter, @Nonnull Type targetType, @Nonnull Class<? extends HttpMessageConverter<?>> converterType) {
         Annotation[] annotations = methodParameter.getDeclaringClass().getAnnotations();
-        if(annotations!=null && annotations.length>0){
+        if (annotations != null && annotations.length > 0) {
             for (Annotation annotation : annotations) {
-                if(annotation instanceof DecryptBody ||
+                if (annotation instanceof DecryptBody ||
                         annotation instanceof AESDecryptBody ||
                         annotation instanceof DESDecryptBody ||
-                        annotation instanceof RSADecryptBody){
+                        annotation instanceof RSADecryptBody) {
                     return true;
                 }
             }
         }
-        return methodParameter.getMethod().isAnnotationPresent(DecryptBody.class) ||
-                methodParameter.getMethod().isAnnotationPresent(AESDecryptBody.class) ||
-                methodParameter.getMethod().isAnnotationPresent(DESDecryptBody.class) ||
-                methodParameter.getMethod().isAnnotationPresent(RSADecryptBody.class);
+        if (Arrays.stream(ReflectUtil.getSuperclasses(methodParameter.getDeclaringClass()))
+                .flatMap(clazz -> Arrays.stream(clazz.getAnnotations()))
+                .anyMatch(annotation -> annotation instanceof DecryptBody ||
+                        annotation instanceof AESDecryptBody ||
+                        annotation instanceof DESDecryptBody ||
+                        annotation instanceof RSADecryptBody)) {
+            return true;
+        }
+        return methodParameter.getMethod() != null &&
+                (methodParameter.getMethod().isAnnotationPresent(DecryptBody.class) ||
+                        methodParameter.getMethod().isAnnotationPresent(AESDecryptBody.class) ||
+                        methodParameter.getMethod().isAnnotationPresent(DESDecryptBody.class) ||
+                        methodParameter.getMethod().isAnnotationPresent(RSADecryptBody.class));
     }
 
     @Override
-    public Object handleEmptyBody(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) {
+    public Object handleEmptyBody(Object body, @Nonnull HttpInputMessage inputMessage,
+                                  @Nonnull MethodParameter parameter, @Nonnull Type targetType,
+                                  @Nonnull Class<? extends HttpMessageConverter<?>> converterType) {
         return body;
     }
 
     @Override
-    public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class<? extends HttpMessageConverter<?>> converterType) throws IOException {
-        if(inputMessage.getBody()==null){
-            return inputMessage;
-        }
+    @Nonnull
+    public HttpInputMessage beforeBodyRead(HttpInputMessage inputMessage, @Nonnull MethodParameter parameter,
+                                           @Nonnull Type targetType,
+                                           @Nonnull Class<? extends HttpMessageConverter<?>> converterType) throws IOException {
+        inputMessage.getBody();
         String body;
         try {
-            body = IOUtils.toString(inputMessage.getBody(),config.getEncoding());
-        }catch (Exception e){
+            body = IOUtils.toString(inputMessage.getBody(), config.getEncoding());
+        } catch (Exception e) {
             throw new DecryptBodyFailException("Unable to get request body data," +
                     " please check if the sending data body or request method is in compliance with the specification." +
                     " (无法获取请求正文数据,请检查发送数据体或请求方法是否符合规范。)");
         }
-        if(body==null || StringUtils.isNullOrEmpty(body)){
+        if (body == null || StringUtils.isNullOrEmpty(body)) {
             throw new DecryptBodyFailException("The request body is NULL or an empty string, so the decryption failed." +
                     " (请求正文为NULL或为空字符串,因此解密失败。)");
         }
         String decryptBody = null;
         DecryptAnnotationInfoBean methodAnnotation = this.getMethodAnnotation(parameter);
-        if(methodAnnotation!=null){
-            decryptBody = switchDecrypt(body,methodAnnotation);
-        }else{
+        if (methodAnnotation != null) {
+            decryptBody = switchDecrypt(body, methodAnnotation);
+        } else {
             DecryptAnnotationInfoBean classAnnotation = this.getClassAnnotation(parameter.getDeclaringClass());
-            if(classAnnotation!=null){
-                decryptBody = switchDecrypt(body,classAnnotation);
+            if (classAnnotation != null) {
+                decryptBody = switchDecrypt(body, classAnnotation);
             }
         }
-        if(decryptBody==null){
+        if (decryptBody == null) {
             throw new DecryptBodyFailException("Decryption error, " +
                     "please check if the selected source data is encrypted correctly." +
                     " (解密错误,请检查选择的源数据的加密方式是否正确。)");
         }
         try {
             InputStream inputStream = IOUtils.toInputStream(decryptBody, config.getEncoding());
-            return new DecryptHttpInputMessage(inputStream,inputMessage.getHeaders());
-        }catch (Exception e){
+            return new DecryptHttpInputMessage(inputStream, inputMessage.getHeaders());
+        } catch (Exception e) {
             throw new DecryptBodyFailException("The string is converted to a stream format exception." +
                     " Please check if the format such as encoding is correct." +
                     " (字符串转换成流格式异常,请检查编码等格式是否正确。)");
@@ -118,24 +138,25 @@ public class DecryptRequestBodyAdvice implements RequestBodyAdvice {
 
     /**
      * 获取方法控制器上的加密注解信息
+     *
      * @param methodParameter 控制器方法
      * @return 加密注解信息
      */
-    private DecryptAnnotationInfoBean getMethodAnnotation(MethodParameter methodParameter){
-        if(methodParameter.getMethod().isAnnotationPresent(DecryptBody.class)){
+    private DecryptAnnotationInfoBean getMethodAnnotation(MethodParameter methodParameter) {
+        if (methodParameter.getMethod().isAnnotationPresent(DecryptBody.class)) {
             DecryptBody decryptBody = methodParameter.getMethodAnnotation(DecryptBody.class);
             return DecryptAnnotationInfoBean.builder()
                     .decryptBodyMethod(decryptBody.value())
                     .key(decryptBody.otherKey())
                     .build();
         }
-        if(methodParameter.getMethod().isAnnotationPresent(DESDecryptBody.class)){
+        if (methodParameter.getMethod().isAnnotationPresent(DESDecryptBody.class)) {
             return DecryptAnnotationInfoBean.builder()
                     .decryptBodyMethod(DecryptBodyMethod.DES)
                     .key(methodParameter.getMethodAnnotation(DESDecryptBody.class).otherKey())
                     .build();
         }
-        if(methodParameter.getMethod().isAnnotationPresent(AESDecryptBody.class)){
+        if (methodParameter.getMethod().isAnnotationPresent(AESDecryptBody.class)) {
             return DecryptAnnotationInfoBean.builder()
                     .decryptBodyMethod(DecryptBodyMethod.AES)
                     .key(methodParameter.getMethodAnnotation(AESDecryptBody.class).otherKey())
@@ -146,32 +167,32 @@ public class DecryptRequestBodyAdvice implements RequestBodyAdvice {
 
     /**
      * 获取类控制器上的加密注解信息
+     *
      * @param clazz 控制器类
      * @return 加密注解信息
      */
-    private DecryptAnnotationInfoBean getClassAnnotation(Class clazz){
-        Annotation[] annotations = clazz.getDeclaredAnnotations();
-        if(annotations!=null && annotations.length>0){
-            for (Annotation annotation : annotations) {
-                if(annotation instanceof DecryptBody){
-                    DecryptBody decryptBody = (DecryptBody) annotation;
-                    return DecryptAnnotationInfoBean.builder()
-                            .decryptBodyMethod(decryptBody.value())
-                            .key(decryptBody.otherKey())
-                            .build();
-                }
-                if(annotation instanceof DESDecryptBody){
-                    return DecryptAnnotationInfoBean.builder()
-                            .decryptBodyMethod(DecryptBodyMethod.DES)
-                            .key(((DESDecryptBody) annotation).otherKey())
-                            .build();
-                }
-                if(annotation instanceof AESDecryptBody){
-                    return DecryptAnnotationInfoBean.builder()
-                            .decryptBodyMethod(DecryptBodyMethod.AES)
-                            .key(((AESDecryptBody) annotation).otherKey())
-                            .build();
-                }
+    private DecryptAnnotationInfoBean getClassAnnotation(Class clazz) {
+        List<Annotation> annotations = new ArrayList<>(Arrays.asList(clazz.getSuperclass().getDeclaredAnnotations()));
+        annotations.addAll(Arrays.asList(clazz.getDeclaredAnnotations()));
+        for (Annotation annotation : annotations) {
+            if (annotation instanceof DecryptBody) {
+                DecryptBody decryptBody = (DecryptBody) annotation;
+                return DecryptAnnotationInfoBean.builder()
+                        .decryptBodyMethod(decryptBody.value())
+                        .key(decryptBody.otherKey())
+                        .build();
+            }
+            if (annotation instanceof DESDecryptBody) {
+                return DecryptAnnotationInfoBean.builder()
+                        .decryptBodyMethod(DecryptBodyMethod.DES)
+                        .key(((DESDecryptBody) annotation).otherKey())
+                        .build();
+            }
+            if (annotation instanceof AESDecryptBody) {
+                return DecryptAnnotationInfoBean.builder()
+                        .decryptBodyMethod(DecryptBodyMethod.AES)
+                        .key(((AESDecryptBody) annotation).otherKey())
+                        .build();
             }
         }
         return null;
@@ -180,21 +201,22 @@ public class DecryptRequestBodyAdvice implements RequestBodyAdvice {
 
     /**
      * 选择加密方式并进行解密
+     *
      * @param formatStringBody 目标解密字符串
-     * @param infoBean 加密信息
+     * @param infoBean         加密信息
      * @return 解密结果
      */
-    private String switchDecrypt(String formatStringBody,DecryptAnnotationInfoBean infoBean){
+    private String switchDecrypt(String formatStringBody, DecryptAnnotationInfoBean infoBean) {
         DecryptBodyMethod method = infoBean.getDecryptBodyMethod();
-        if(method==null) throw new DecryptMethodNotFoundException();
+        if (method == null) throw new DecryptMethodNotFoundException();
         String key = infoBean.getKey();
-        if(method == DecryptBodyMethod.DES){
-            key = CheckUtils.checkAndGetKey(config.getDesKey(),key,"DES-KEY");
-            return DESEncryptUtil.decrypt(formatStringBody,key);
+        if (method == DecryptBodyMethod.DES) {
+            key = CheckUtils.checkAndGetKey(config.getDesKey(), key, "DES-KEY");
+            return DESEncryptUtil.decrypt(formatStringBody, key);
         }
-        if(method == DecryptBodyMethod.AES){
-            key = CheckUtils.checkAndGetKey(config.getAesKey(),key,"AES-KEY");
-            return AESEncryptUtil.decrypt(formatStringBody,key);
+        if (method == DecryptBodyMethod.AES) {
+            key = CheckUtils.checkAndGetKey(config.getAesKey(), key, "AES-KEY");
+            return AESEncryptUtil.decrypt(formatStringBody, key);
         }
         throw new DecryptBodyFailException();
     }

+ 11 - 5
src/main/java/com/izouma/jmrh/config/WebMvcConfig.java

@@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.web.servlet.config.annotation.CorsRegistry;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 import springfox.documentation.builders.ApiInfoBuilder;
@@ -12,6 +13,8 @@ import springfox.documentation.builders.RequestHandlerSelectors;
 import springfox.documentation.spi.DocumentationType;
 import springfox.documentation.spring.web.plugins.Docket;
 
+import javax.annotation.Nonnull;
+
 @Configuration
 public class WebMvcConfig implements WebMvcConfigurer {
     @Value("${storage.local_path}")
@@ -30,11 +33,11 @@ public class WebMvcConfig implements WebMvcConfigurer {
     public Docket createApi() {
         return new Docket(DocumentationType.SWAGGER_2)
                 .apiInfo(new ApiInfoBuilder()
-                                 .title("接口文档")
-                                 .version("1.0.0")
-                                 .termsOfServiceUrl("#")
-                                 .description("接口文档")
-                                 .build())
+                        .title("接口文档")
+                        .version("1.0.0")
+                        .termsOfServiceUrl("#")
+                        .description("接口文档")
+                        .build())
                 .select()
                 .apis(RequestHandlerSelectors.basePackage("com.izouma.jmrh.web"))
                 .paths(PathSelectors.any())
@@ -72,4 +75,7 @@ public class WebMvcConfig implements WebMvcConfigurer {
                 .exposedHeaders("Content-Disposition,Content-Encrypted");
     }
 
+    @Override
+    public void addInterceptors(@Nonnull InterceptorRegistry registry) {
+    }
 }

+ 14 - 1
src/main/java/com/izouma/jmrh/exception/GlobalExceptionHandler.java

@@ -1,5 +1,6 @@
 package com.izouma.jmrh.exception;
 
+import cn.licoy.encryptbody.exception.DecryptBodyFailException;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.http.HttpStatus;
 import org.springframework.transaction.TransactionSystemException;
@@ -60,7 +61,8 @@ public class GlobalExceptionHandler {
                 ConstraintViolationException violationException = (ConstraintViolationException) e.getCause()
                         .getCause();
                 message = violationException.getConstraintViolations().stream()
-                        .map(constraintViolation -> constraintViolation.getPropertyPath() + constraintViolation.getMessage())
+                        .map(constraintViolation -> constraintViolation.getPropertyPath() + constraintViolation
+                                .getMessage())
                         .collect(Collectors.joining(","));
                 log.error(message);
             }
@@ -146,4 +148,15 @@ public class GlobalExceptionHandler {
         log.error(e.getMessage());
         return map;
     }
+
+    @ExceptionHandler(value = DecryptBodyFailException.class)
+    @ResponseStatus(HttpStatus.BAD_REQUEST)
+    @ResponseBody
+    public Map<String, Object> decryptExceptionHandler(DecryptBodyFailException e) {
+        Map<String, Object> map = new HashMap<>();
+        map.put("code", -1);
+        map.put("error", e.getMessage());
+        log.error("decryptExceptionHandler", e);
+        return map;
+    }
 }

+ 5 - 4
src/main/java/com/izouma/jmrh/web/AuthenticationController.java

@@ -1,6 +1,9 @@
 package com.izouma.jmrh.web;
 
+import cn.licoy.encryptbody.annotation.decrypt.DecryptBody;
+import cn.licoy.encryptbody.annotation.encrypt.DESEncryptBody;
 import cn.licoy.encryptbody.annotation.encrypt.EncryptBody;
+import cn.licoy.encryptbody.enums.DecryptBodyMethod;
 import cn.licoy.encryptbody.enums.EncryptBodyMethod;
 import com.izouma.jmrh.domain.LoginLog;
 import com.izouma.jmrh.domain.User;
@@ -23,10 +26,7 @@ import org.springframework.security.authentication.DisabledException;
 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
 import org.springframework.security.core.userdetails.UserDetails;
 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.time.LocalDateTime;
 import java.util.Objects;
@@ -39,6 +39,7 @@ import java.util.concurrent.TimeUnit;
 @RestController
 @RequestMapping("/auth")
 @EncryptBody(EncryptBodyMethod.AES)
+@DecryptBody(DecryptBodyMethod.AES)
 public class AuthenticationController {
     private AuthenticationManager authenticationManager;
     private JwtTokenUtil          jwtTokenUtil;

+ 3 - 0
src/main/java/com/izouma/jmrh/web/BaseController.java

@@ -1,6 +1,8 @@
 package com.izouma.jmrh.web;
 
+import cn.licoy.encryptbody.annotation.decrypt.DecryptBody;
 import cn.licoy.encryptbody.annotation.encrypt.EncryptBody;
+import cn.licoy.encryptbody.enums.DecryptBodyMethod;
 import cn.licoy.encryptbody.enums.EncryptBodyMethod;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.izouma.jmrh.annotations.Searchable;
@@ -27,6 +29,7 @@ import java.util.regex.Pattern;
 @SuppressWarnings("ALL")
 @Slf4j
 @EncryptBody(EncryptBodyMethod.AES)
+@DecryptBody(DecryptBodyMethod.AES)
 public class BaseController {
     public static PageRequest toPageRequest(PageQuery pageQuery) {
         PageRequest pageRequest;

+ 1 - 0
src/main/java/com/izouma/jmrh/web/OrgInfoController.java

@@ -1,5 +1,6 @@
 package com.izouma.jmrh.web;
 
+import cn.licoy.encryptbody.annotation.decrypt.AESDecryptBody;
 import com.izouma.jmrh.annotations.OperLog;
 import com.izouma.jmrh.domain.OrgInfo;
 import com.izouma.jmrh.domain.User;

+ 15 - 2
src/main/jmrh/src/plugins/http.js

@@ -24,6 +24,15 @@ function decrypt(content) {
     return decrypted.toString(CryptoJS.enc.Utf8);
 }
 
+function encrypt(content) {
+    const key = CryptoJS.enc.Hex.parse('2181E9E80460B852859EE455AC5203D9');
+    var encrypted = CryptoJS.AES.encrypt(content, key, {
+        mode: CryptoJS.mode.ECB,
+        padding: CryptoJS.pad.Pkcs7
+    });
+    return encrypted.ciphertext.toString(CryptoJS.enc.Hex);
+}
+
 axiosInstance.interceptors.request.use(
     function(config) {
         config.headers = config.headers || {};
@@ -93,15 +102,19 @@ export default {
             },
             post(url, body, options) {
                 options = options || {};
+                options.headers = options.headers || {};
                 body = body || {};
                 if (!(body instanceof FormData)) {
-                    if (options.body !== 'json') {
+                    if (options.body === 'json') {
+                        body = encrypt(JSON.stringify(body));
+                        options.headers['content-type'] = 'application/json';
+                    } else {
                         body = qs.stringify(body);
                     }
                 }
                 return new Promise((resolve, reject) => {
                     axiosInstance
-                        .post(url, body, { withCredentials: true })
+                        .post(url, body, { withCredentials: true, headers: { ...options.headers } })
                         .then(res => {
                             resolve(res.data);
                         })

+ 14 - 1
src/main/vue/src/plugins/http.js

@@ -24,6 +24,15 @@ function decrypt(content) {
     return decrypted.toString(CryptoJS.enc.Utf8);
 }
 
+function encrypt(content) {
+    const key = CryptoJS.enc.Hex.parse('2181E9E80460B852859EE455AC5203D9');
+    var encrypted = CryptoJS.AES.encrypt(content, key, {
+        mode: CryptoJS.mode.ECB,
+        padding: CryptoJS.pad.Pkcs7
+    });
+    return encrypted.ciphertext.toString(CryptoJS.enc.Hex);
+}
+
 axiosInstance.interceptors.request.use(
     function(config) {
         config.headers = config.headers || {};
@@ -94,9 +103,13 @@ export default {
             },
             post(url, body, options) {
                 options = options || {};
+                options.headers = options.headers || {};
                 body = body || {};
                 if (!(body instanceof FormData)) {
-                    if (options.body !== 'json') {
+                    if (options.body === 'json') {
+                        body = encrypt(JSON.stringify(body));
+                        options.headers['content-type'] = 'application/json';
+                    } else {
                         body = qs.stringify(body);
                     }
                 }