This commit is contained in:
insanity 2018-07-02 20:37:23 +09:00
parent 29629b144f
commit d9576bf275
2 changed files with 16 additions and 15 deletions

View File

@ -27,6 +27,8 @@ import com.loafle.overflow.service.central.probe.ProbeHostService;
import com.loafle.overflow.service.central.probe.ProbeService;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -36,7 +38,6 @@ import inet.ipaddr.IPAddressString;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import javax.transaction.Transactional;
@ -156,7 +157,7 @@ public class CentralNoAuthProbeService implements NoAuthProbeService {
DomainMember domainMember = domainMemberService.readByMemberEmail(memberEmail);
Probe probe = new Probe();
probe.setEncryptionKey(UUID.randomUUID().toString() + UUID.randomUUID().toString());
probe.setEncryptionKey(RandomStringUtils.randomAlphanumeric(8));
probe.setProbeKey(GenerateKey.getKey());
probe.setDomain(new Domain(apiKey.getDomain().getId()));
probe.setAuthorizeMember(new Member(domainMember.getMember().getId()));

View File

@ -69,15 +69,16 @@ public class CentralSensorConfigService {
}
private String toEncryptString(SensorConfig sensorConfig, String encryptKey) throws OverflowException {
try {
String sensorConfigJsonStr = this.objectMapper.writeValueAsString(sensorConfig);
// gzip
ByteArrayOutputStream obj = new ByteArrayOutputStream();
GZIPOutputStream gzip = new GZIPOutputStream(obj);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
GZIPOutputStream gzip = new GZIPOutputStream(bos);
gzip.write(sensorConfigJsonStr.getBytes("UTF-8"));
gzip.flush();
gzip.close();
byte[] compressedByte = obj.toByteArray();
byte[] compressedByte = bos.toByteArray();
// DES encryption
Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
@ -98,22 +99,21 @@ public class CentralSensorConfigService {
/*
* private String testDecrypt(String encryptKey, String encrypted) throws
* OverflowException { try { byte[] inputBytes =
* Base64.getDecoder().decode(encrypted.getBytes());
*
* Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); SecretKeyFactory
* keyFactory = SecretKeyFactory.getInstance("DES"); DESKeySpec desKeySpec = new
* 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);
*
* 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); } }
*/