Commit 56dd266f by luozhenzhen

修改jar包下载接口

parent 367c0cae
......@@ -306,7 +306,8 @@ public class DataImportController {
"\t\t\t\"type\": \"oc\"\n" +
"\t\t}\n" +
"\t],\n" +
"\"period\":1800"+
"\"period\":1800,"+
"\"heart_period\":30"+
"}";
str = str.replaceAll("\n","");
......@@ -744,7 +745,8 @@ public class DataImportController {
"\"jarurl\":\"https://39.104.115.147:10081/downloadFile\","+
"\"key\":\"5662e7c3d61fd5e0e67acd8bace6d1b0\""+
"},"+
"\"period\":1800"+
"\"period\":1800,"+
"\"heart_period\":30"+
"}";
str = str.replaceAll("\n","");
str = str.replaceAll("\t","");
......
......@@ -104,25 +104,29 @@ public class DevicecheatController {
}
@RequestMapping(value = "/encryptorFile", method = RequestMethod.GET)
@ResponseBody
public ResultObject deviceconf() throws Exception {
String sourceFilePath = "/data/application/deviceCheck/updateJar/update.jar";
String destFilePath = "/data/application/deviceCheck/updateJar/encryptorFile/update.jar";
// @RequestMapping(value = "/encryptorFile", method = RequestMethod.GET)
// @ResponseBody
// public ResultObject deviceconf() throws Exception {
//// String sourceFilePath = "/data/application/deviceCheck/updateJar/update.jar";
//// String destFilePath = "/data/application/deviceCheck/updateJar/encryptorFile/update.jar";
// String sourceFilePath = "C:\\Users\\reyun\\Desktop\\update.jar";
// String destFilePath = "C:\\Users\\reyun\\Desktop\\update_2.jar";
String key = "5662e7c3d61fd5e0e67acd8bace6d1b0";
FileEncryptor.decryptFile(key,sourceFilePath,destFilePath);
return new ResultObject(ResultStatus.SUCCESS);
}
// String key = "5662e7c3d61fd5e0e67acd8bace6d1b0";
// FileEncryptor.encryptFile(key,sourceFilePath,destFilePath);
// return new ResultObject(ResultStatus.SUCCESS);
// }
@RequestMapping(value = "/downloadFile", method = RequestMethod.GET)
@ResponseBody
public ResultObject downloadFile(HttpServletResponse response, String fileName) throws Exception {
String sourceFilePath = "/data/application/deviceCheck/updateJar/encryptorFile/update.jar";
public void downloadFile(HttpServletResponse response, String fileName) throws Exception {
// String sourceFilePath = "/data/application/deviceCheck/updateJar/encryptorFile/update.jar";
// String sourceFilePath = "C:\\Users\\reyun\\Desktop\\update_2.jar";
// String sourceFilePath = "C:\\Users\\reyun\\Desktop\\update.jar";
String sourceFilePath = "/data/application/deviceCheck/updateJar/update.jar";
if(StringUtils.isEmpty(fileName)){
fileName = "default.jar";
}
FileEncryptor.downloadFileToPath(sourceFilePath,fileName, response);
return new ResultObject(ResultStatus.SUCCESS);
}
@RequestMapping(value = "/getIp", method = RequestMethod.GET)
......
......@@ -14,6 +14,9 @@ import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URLEncoder;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.security.Key;
import java.util.Random;
......@@ -51,19 +54,34 @@ public class FileEncryptor {
OutputStream out = new FileOutputStream(destFile);
byte[] data = inputStreamToByte(in);
byte[] aesData = SpecialSecret.aes256EncodeB(data, key.getBytes());
ByteArrayInputStream cin = StringToInputStream(aesData);
//base64
// char[] aesData = DeformedBase64.encode(data);
// ByteArrayInputStream cin = StringToInputStream(getBytes(aesData));
ByteArrayInputStream cin = StringToInputStream(data);
// byte[] aesData = SpecialSecret.aes256EncodeB(data, key.getBytes());
// ByteArrayInputStream cin = StringToInputStream(aesData);
// byte[] raw = key.getBytes();
// SecretKeySpec secretKeySpec = new SecretKeySpec(raw, ALGORITHM);
// Cipher cipher = Cipher.getInstance(ALGORITHM);
// cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
// CipherInputStream cin = new CipherInputStream(in, cipher);
byte[] cache = new byte[CACHE_SIZE];
int nRead = 0;
while ((nRead = cin.read(cache)) != -1) {
out.write(cache, 0, nRead);
while ((nRead = cin.read()) != -1) {
out.write(nRead);
out.flush();
}
// byte[] cache = new byte[CACHE_SIZE];
// int nRead = 0;
// while ((nRead = cin.read(cache)) != -1) {
// out.write(cache, 0, nRead);
// out.flush();
// }
out.close();
cin.close();
in.close();
......@@ -71,7 +89,7 @@ public class FileEncryptor {
}
public static byte[] inputStreamToByte(InputStream input) throws IOException{
byte[] b = new byte[4096];
byte[] b = new byte[input.available()];
for (int n; (n = input.read(b)) != -1;) {
}
return b;
......@@ -83,6 +101,15 @@ public class FileEncryptor {
return is;
}
public static byte[] getBytes(char[] chars) {
Charset cs = Charset.forName("UTF-8");
CharBuffer cb = CharBuffer.allocate(chars.length);
cb.put(chars);
cb.flip();
ByteBuffer bb = cs.encode(cb);
return bb.array();
}
/**
* <p>
......@@ -161,12 +188,13 @@ public class FileEncryptor {
if (sourceFile.exists() && sourceFile.isFile()) {
FileInputStream in = new FileInputStream(sourceFile);
byte[] data = inputStreamToByte(in);
char[] aesData = DeformedBase64.encode(data);
ByteArrayInputStream cin = StringToInputStream(getBytes(aesData));
out = resp.getOutputStream();
byte[] cache = new byte[CACHE_SIZE];
int nRead = 0;
while ((nRead = in.read(cache)) != -1) {
out.write(cache, 0, nRead);
while ((nRead = cin.read()) != -1) {
out.write(nRead);
out.flush();
}
}
......
......@@ -2,7 +2,7 @@ server.port=8081
spring.data.mongodb.host=192.168.168.81
spring.data.mongodb.port=8763
spring.data.mongodb.database=device
server.ssl.key-store=classpath:keystore.p12
server.ssl.key-store=classpath:keystore_win.p12
server.ssl.key-store-password=123456
server.ssl.key-store-type=PKCS12
server.ssl.key-alias= tomcat
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment