dev #525
@ -1,9 +1,7 @@
|
||||
package com.interplug.qcast.biz.pwrGnrSimulation;
|
||||
|
||||
import com.interplug.qcast.biz.estimate.dto.EstimateRequest;
|
||||
import com.interplug.qcast.biz.pwrGnrSimulation.dto.PwrGnrSimGuideResponse;
|
||||
import com.interplug.qcast.biz.pwrGnrSimulation.dto.PwrGnrSimRequest;
|
||||
import com.interplug.qcast.biz.pwrGnrSimulation.dto.PwrGnrSimResponse;
|
||||
import com.interplug.qcast.biz.pwrGnrSimulation.dto.*;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
@ -47,4 +45,11 @@ public class PwrGnrSimController {
|
||||
throws Exception {
|
||||
pwrGnrSimService.excelDownload(request, response, estimateRequest);
|
||||
}
|
||||
|
||||
@Operation(description = "발전시뮬레이션 판매점정보 암호화를 처리한다.")
|
||||
@GetMapping("/encData")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public PwrGnrSimEncResponse selectPwrGnrSimulationEncData(PwrGnrSimEncRequest pwrGnrSimEncRequest) throws Exception {
|
||||
return pwrGnrSimService.selectPwrGnrSimulationEncData(pwrGnrSimEncRequest);
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ import com.interplug.qcast.biz.pwrGnrSimulation.dto.*;
|
||||
import com.interplug.qcast.config.Exception.ErrorCode;
|
||||
import com.interplug.qcast.config.Exception.QcastException;
|
||||
import com.interplug.qcast.config.message.Messages;
|
||||
import com.interplug.qcast.util.EncryptUtil;
|
||||
import com.interplug.qcast.util.ExcelUtil;
|
||||
import com.interplug.qcast.util.InterfaceQsp;
|
||||
import com.interplug.qcast.util.PdfUtil;
|
||||
@ -2614,4 +2615,12 @@ public class PwrGnrSimService {
|
||||
}
|
||||
}
|
||||
|
||||
public PwrGnrSimEncResponse selectPwrGnrSimulationEncData(PwrGnrSimEncRequest pwrGnrSimEncRequest) throws Exception {
|
||||
PwrGnrSimEncResponse encDataResponse = new PwrGnrSimEncResponse();
|
||||
|
||||
encDataResponse.setEncSaleStoreId(EncryptUtil.encryptAes256(pwrGnrSimEncRequest.getSaleStoreId()));
|
||||
encDataResponse.setEncUserId(EncryptUtil.encryptAes256(pwrGnrSimEncRequest.getUserId()));
|
||||
|
||||
return encDataResponse;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
package com.interplug.qcast.biz.pwrGnrSimulation.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PwrGnrSimEncRequest {
|
||||
@Schema(description = "판매점ID")
|
||||
private String saleStoreId;
|
||||
|
||||
@Schema(description = "사용자아이디")
|
||||
private String userId;
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package com.interplug.qcast.biz.pwrGnrSimulation.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PwrGnrSimEncResponse {
|
||||
@Schema(description = "암호화 판매점 아이디")
|
||||
private String encSaleStoreId;
|
||||
|
||||
@Schema(description = "암호화 로그인 아이디")
|
||||
private String encUserId;
|
||||
}
|
||||
127
src/main/java/com/interplug/qcast/util/EncryptUtil.java
Normal file
127
src/main/java/com/interplug/qcast/util/EncryptUtil.java
Normal file
@ -0,0 +1,127 @@
|
||||
package com.interplug.qcast.util;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Base64;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class EncryptUtil {
|
||||
/** 초기화 비밀번호 */
|
||||
@Value("${qsp.aes256.key}")
|
||||
static String loginPasswordAesKey;
|
||||
|
||||
@Value("${qsp.aes256.key}")
|
||||
public void setLoginPasswordAesKey(String value) {
|
||||
loginPasswordAesKey = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 비밀번호를 암호화하는 기능(복호화가 되면 안되므로 SHA-256 인코딩 방식 적용)
|
||||
*
|
||||
* @param password 암호화될 패스워드
|
||||
* @param id salt로 사용될 사용자 ID 지정
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String encryptSha256(String password, String id) {
|
||||
if (password == null) {
|
||||
return "";
|
||||
}
|
||||
String enStr = null;
|
||||
|
||||
try {
|
||||
byte[] hashValue = null; // 해쉬값
|
||||
|
||||
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
||||
|
||||
md.reset();
|
||||
md.update(id.getBytes());
|
||||
|
||||
hashValue = md.digest(password.getBytes());
|
||||
enStr = new String(Base64.getEncoder().encode(hashValue));
|
||||
} catch (Exception e) {
|
||||
log.error("Sha Util Encrypt Error", e);
|
||||
}
|
||||
return enStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* AES-256 암호화
|
||||
* @param keyword
|
||||
* @return
|
||||
*/
|
||||
public static String encryptAes256(String keyword) {
|
||||
|
||||
return encryptAes256(keyword, loginPasswordAesKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* AES-256 암호화
|
||||
* @param keyword
|
||||
* @return
|
||||
*/
|
||||
public static String encryptAes256(String keyword, String loginPasswordKey) {
|
||||
if(StringUtils.isBlank(keyword)) {
|
||||
return null;
|
||||
}
|
||||
String enStr = null;
|
||||
try {
|
||||
byte[] keyData = loginPasswordAesKey.getBytes();
|
||||
|
||||
SecretKey secureKey = new SecretKeySpec(keyData, "AES");
|
||||
|
||||
Cipher c = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||
c.init(Cipher.ENCRYPT_MODE, secureKey, new IvParameterSpec(loginPasswordKey.substring(0, 16).getBytes()));
|
||||
|
||||
byte[] encrypted = c.doFinal(keyword.getBytes("UTF-8"));
|
||||
enStr = new String(Base64.getEncoder().encode(encrypted));
|
||||
} catch (Exception e) {
|
||||
log.error("AES Util Encrypt Error", e);
|
||||
}
|
||||
return enStr;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* AES-256 복호화
|
||||
* @param keyword
|
||||
* @return
|
||||
*/
|
||||
public static String decryptAes256(String keyword) {
|
||||
|
||||
return decryptAes256(keyword, loginPasswordAesKey);
|
||||
}
|
||||
/**
|
||||
* AES-256 복호화
|
||||
* @param keyword
|
||||
* @return
|
||||
*/
|
||||
public static String decryptAes256(String keyword, String loginPasswordKey) {
|
||||
if(StringUtils.isBlank(keyword)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String deStr = null;
|
||||
try {
|
||||
byte[] keyData = loginPasswordAesKey.getBytes();
|
||||
SecretKey secureKey = new SecretKeySpec(keyData, "AES");
|
||||
Cipher c = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||
c.init(Cipher.DECRYPT_MODE, secureKey, new IvParameterSpec(loginPasswordKey.substring(0, 16).getBytes("UTF-8")));
|
||||
|
||||
byte[] byteStr = Base64.getDecoder().decode(keyword.getBytes());
|
||||
deStr = new String(c.doFinal(byteStr), "UTF-8");
|
||||
} catch (Exception e) {
|
||||
log.error("AES Util Decrypt Error", e);
|
||||
}
|
||||
return deStr;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user