encrypt
This commit is contained in:
		
							parent
							
								
									29629b144f
								
							
						
					
					
						commit
						d9576bf275
					
				@ -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()));
 | 
			
		||||
 | 
			
		||||
@ -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,14 +99,13 @@ public class CentralSensorConfigService {
 | 
			
		||||
  /*
 | 
			
		||||
   * private String testDecrypt(String encryptKey, String encrypted) throws
 | 
			
		||||
   * OverflowException { try { byte[] inputBytes =
 | 
			
		||||
   * Base64.getDecoder().decode(encrypted.getBytes());
 | 
			
		||||
   * Base64.getDecoder().decode(encrypted);
 | 
			
		||||
   * 
 | 
			
		||||
   * Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); SecretKeyFactory
 | 
			
		||||
   * keyFactory = SecretKeyFactory.getInstance("DES"); DESKeySpec desKeySpec = new
 | 
			
		||||
   * 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
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user