|
@@ -19,6 +19,7 @@ import cn.com.qmth.stmms.ms.core.repository.StudentRepo;
|
|
|
import cn.com.qmth.stmms.ms.core.repository.WorkRepo;
|
|
|
import cn.com.qmth.stmms.ms.core.vo.Subject;
|
|
|
import net.sf.json.JSONObject;
|
|
|
+import org.apache.commons.codec.binary.Hex;
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
import org.assertj.core.util.Strings;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -31,6 +32,7 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.io.*;
|
|
|
+import java.security.MessageDigest;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.function.Consumer;
|
|
@@ -141,7 +143,7 @@ public class CollectApi {
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
-// File srcFile = new File("/Users/king/stmms-ms/static/images/1/SM/1/1901130045.jpg"); //初始文件
|
|
|
+ File srcFile = new File("/Users/king/stmms-ms/static/images/2/SM/1/1901040150.jpg"); //初始文件
|
|
|
|
|
|
/**
|
|
|
* 上传原图(图片加密)
|
|
@@ -174,21 +176,34 @@ public class CollectApi {
|
|
|
if (!out.exists()) {
|
|
|
out.mkdirs();
|
|
|
}
|
|
|
-
|
|
|
String imageMd5 = MD5Util.getImageRuleMd5(workId, subject.ordinal(), student.getAreaCode(), student.getExamNumber(), student.getId());
|
|
|
File sheetFile = new File(sheetDir + File.separator + imageMd5 + ".jpg");
|
|
|
LOGGER.info("sheet存放目录:{}", sheetFile.getPath());
|
|
|
outputStream = new FileOutputStream(sheetFile);
|
|
|
- SystemConstant.writeStream(inputStream, outputStream);
|
|
|
+// SystemConstant.writeStream(inputStream, outputStream);
|
|
|
+ byte[] bytes = new byte[1024 * 8];
|
|
|
+ byte[] bytesEnc = new byte[1024 * 8];
|
|
|
+ int index = 0;
|
|
|
+ MessageDigest MD5 = MessageDigest.getInstance("MD5");//MD5值
|
|
|
+ while ((index = inputStream.read(bytes)) != -1) {
|
|
|
+ //将字节数组的数据全部写入到输出流中
|
|
|
+ for (int i = 0; i < index; i++) {
|
|
|
+ //通过异或运算加密
|
|
|
+ bytesEnc[i] = (byte) (bytes[i] ^ SystemConstant.SECRET_KEY);
|
|
|
+ }
|
|
|
+ outputStream.write(bytesEnc, 0, index);
|
|
|
+ MD5.update(bytes, 0, index);
|
|
|
+ }
|
|
|
long end = System.currentTimeMillis();
|
|
|
LOGGER.info("生成原图耗时:{}", (end - start) / 1000 + "s");
|
|
|
|
|
|
-// String md5 = request.getHeader("md5");
|
|
|
+ String md5 = request.getHeader("md5");
|
|
|
// FileInputStream in = new FileInputStream(sheetFile);
|
|
|
-// String sheetMD5 = DigestUtils.md5Hex(in);
|
|
|
-// if (!md5.equalsIgnoreCase(sheetMD5)) {
|
|
|
-// throw new Exception("图片md5值不一致");
|
|
|
-// }
|
|
|
+ String sheetMD5 = new String(Hex.encodeHex(MD5.digest()));
|
|
|
+ LOGGER.info("request里的MD5,生成的MD5:{}", md5, sheetMD5);
|
|
|
+ if (!md5.equalsIgnoreCase(sheetMD5)) {
|
|
|
+ throw new Exception("图片md5值不一致");
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
} finally {
|
|
@@ -243,6 +258,7 @@ public class CollectApi {
|
|
|
int index = 0;
|
|
|
byte[] bytes = new byte[1024 * 8];
|
|
|
byte[] bytesEnc = new byte[1024 * 8];
|
|
|
+ MessageDigest MD5 = MessageDigest.getInstance("MD5");//MD5值
|
|
|
while ((index = inputStream.read(bytes)) != -1) {
|
|
|
//将字节数组的数据全部写入到输出流中
|
|
|
for (int i = 0; i < index; i++) {
|
|
@@ -251,8 +267,9 @@ public class CollectApi {
|
|
|
}
|
|
|
outputStream.write(bytesEnc, 0, index);
|
|
|
outputStreamTemp.write(bytes, 0, index);
|
|
|
+ MD5.update(bytes, 0, index);
|
|
|
}
|
|
|
-
|
|
|
+ LOGGER.info("生成的MD5:{}", new String(Hex.encodeHex(MD5.digest())));
|
|
|
//生成缩略图
|
|
|
String thumbDir = systemConfig.getThumbDir() + File.separator + workId + File.separator + subject
|
|
|
+ File.separator + student.getAreaCode();
|
|
@@ -273,7 +290,7 @@ public class CollectApi {
|
|
|
inputStream = new ByteArrayInputStream(os.toByteArray());
|
|
|
|
|
|
//原图删除
|
|
|
-// imageFileTemp.delete();
|
|
|
+ imageFileTemp.delete();
|
|
|
// inputStream = new FileInputStream(thumbFileTemp);
|
|
|
//缩略图删除
|
|
|
// thumbFileTemp.delete();
|
|
@@ -281,14 +298,13 @@ public class CollectApi {
|
|
|
long end = System.currentTimeMillis();
|
|
|
LOGGER.info("生成原图和缩略图耗时:{}", (end - start) / 1000 + "s");
|
|
|
|
|
|
-// String md5 = request.getHeader("md5");
|
|
|
+ String md5 = request.getHeader("md5");
|
|
|
// FileInputStream in = new FileInputStream(imageFileTemp);
|
|
|
-// String sliceMD5 = DigestUtils.md5Hex(in);
|
|
|
-// //原图删除
|
|
|
- imageFileTemp.delete();
|
|
|
-// if (!md5.equalsIgnoreCase(sliceMD5)) {
|
|
|
-// throw new Exception("图片md5值不一致");
|
|
|
-// }
|
|
|
+ String sliceMD5 = new String(Hex.encodeHex(MD5.digest()));
|
|
|
+ LOGGER.info("request里的MD5,生成的MD5:{}", md5, sliceMD5);
|
|
|
+ if (!md5.equalsIgnoreCase(sliceMD5)) {
|
|
|
+ throw new Exception("图片md5值不一致");
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
} finally {
|