From ffcc2407cba1b26a00e0a21b8e69e288ceb4fc3d Mon Sep 17 00:00:00 2001 From: insanity Date: Mon, 2 Jul 2018 21:10:49 +0900 Subject: [PATCH] sensorconfig encryption --- .../sensor/service/CentralSensorConfigService.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorConfigService.java b/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorConfigService.java index a235c42..2e327a0 100644 --- a/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorConfigService.java +++ b/src/main/java/com/loafle/overflow/central/module/sensor/service/CentralSensorConfigService.java @@ -73,12 +73,13 @@ public class CentralSensorConfigService { try { String sensorConfigJsonStr = this.objectMapper.writeValueAsString(sensorConfig); // gzip - ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ByteArrayOutputStream bos = new ByteArrayOutputStream(sensorConfigJsonStr.length()); GZIPOutputStream gzip = new GZIPOutputStream(bos); gzip.write(sensorConfigJsonStr.getBytes("UTF-8")); gzip.flush(); gzip.close(); byte[] compressedByte = bos.toByteArray(); + bos.close(); // DES encryption Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); @@ -100,20 +101,20 @@ public class CentralSensorConfigService { * private String testDecrypt(String encryptKey, String encrypted) throws * OverflowException { try { byte[] inputBytes = * Base64.getDecoder().decode(encrypted); - * + * * Cipher cipher = Cipher.getInstance("DES"); SecretKeyFactory keyFactory = * SecretKeyFactory.getInstance("DES"); DESKeySpec desKeySpec = new * DESKeySpec(encryptKey.getBytes()); cipher.init(Cipher.DECRYPT_MODE, * keyFactory.generateSecret(desKeySpec)); byte[] outputBytes = * cipher.doFinal(inputBytes); - * + * * GZIPInputStream gis = new GZIPInputStream(new * ByteArrayInputStream(outputBytes)); BufferedReader bf = new * BufferedReader(new InputStreamReader(gis, "UTF-8")); String result = ""; * String line; while ((line = bf.readLine()) != null) { result += line; } - * + * * return result; - * + * * } catch (Exception e) { throw new OverflowException("", e); } } */