wangwei 5 tahun lalu
induk
melakukan
6d8c6e7006

+ 32 - 1
src/main/java/cn/com/qmth/examcloud/bridge/modules/swjtu/controller/SwjtuController.java

@@ -3,6 +3,8 @@ package cn.com.qmth.examcloud.bridge.modules.swjtu.controller;
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.commons.lang3.StringUtils;
@@ -17,6 +19,7 @@ import org.springframework.web.bind.annotation.RestController;
 import com.google.common.collect.Maps;
 
 import cn.com.qmth.examcloud.commons.exception.StatusException;
+import cn.com.qmth.examcloud.commons.util.JsonUtil;
 import cn.com.qmth.examcloud.commons.util.StringUtil;
 import cn.com.qmth.examcloud.core.oe.admin.api.ExamScoreDataCloudService;
 import cn.com.qmth.examcloud.core.oe.admin.api.bean.ScoreDataBean;
@@ -100,8 +103,12 @@ public class SwjtuController {
 		} catch (Exception e) {
 			map.put("exception", "500");
 		}
+		String result = JsonUtil.toJson(map);
+		if (encrypt) {
+			result = encrypt(JsonUtil.toJson(result));
+		}
 
-		ResponseEntity<Map<String, Object>> entity = ResponseEntity.status(HttpStatus.OK).body(map);
+		ResponseEntity<String> entity = ResponseEntity.status(HttpStatus.OK).body(result);
 		return entity;
 	}
 
@@ -123,4 +130,28 @@ public class SwjtuController {
 		return infoMap;
 	}
 
+	@SuppressWarnings("restriction")
+	public static String byte2base64(byte[] b) {
+		return new sun.misc.BASE64Encoder().encode(b);
+	}
+
+	private static final String AES = "AES";
+
+	private static final String CRYPT_KEY = "ZwFOcwz6QtIQ983m";
+
+	public final static String encrypt(String data) {
+		try {
+			return byte2base64(encrypt(data.getBytes("ISO-8859-1"), CRYPT_KEY));
+		} catch (Exception e) {
+		}
+		return null;
+	}
+
+	public static byte[] encrypt(byte[] src, String key) throws Exception {
+		Cipher cipher = Cipher.getInstance(AES);
+		SecretKeySpec securekey = new SecretKeySpec(key.getBytes(), AES);
+		cipher.init(Cipher.ENCRYPT_MODE, securekey);// 设置密钥和加密形式
+		return cipher.doFinal(src);
+	}
+
 }