diff --git a/src/main/java/geoinfo/com/CryptoUtil.java b/src/main/java/geoinfo/com/CryptoUtil.java index 0fd2c72e..b2562b19 100644 --- a/src/main/java/geoinfo/com/CryptoUtil.java +++ b/src/main/java/geoinfo/com/CryptoUtil.java @@ -22,7 +22,29 @@ import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.PBEKeySpec; import javax.crypto.spec.SecretKeySpec; +import egovframework.com.cmm.service.EgovProperties; + public class CryptoUtil { + // ===== [고정 키 AES - 빠른 버전] ===== + private static SecretKeySpec FIXED_SECRET_KEY; + + /** + * encryptQuickAES key + * 서버 기동시 1회 자동 실행됨 + */ + static { + try { + String key = EgovProperties.getProperty("SHA256.secret_key").trim(); + + MessageDigest sha = MessageDigest.getInstance("SHA-256"); + byte[] keyBytes = sha.digest(key.getBytes("UTF-8")); + + FIXED_SECRET_KEY = new SecretKeySpec(keyBytes, "AES"); + } catch (Exception e) { + throw new RuntimeException("CryptoUtil AES key initialization failed", e); + } + } + /** * MD5 로 해시 한다. * @@ -142,4 +164,27 @@ public class CryptoUtil { byte[] decryptedTextBytes = cipher.doFinal(encryoptedTextBytes); return new String(decryptedTextBytes); } + + + /** + * AES 고정 키 암호화 (빠름) + */ + public static String encryptQuickAES(String plainText) throws Exception { + Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); + cipher.init(Cipher.ENCRYPT_MODE, FIXED_SECRET_KEY); + return Base64.getEncoder() + .encodeToString(cipher.doFinal(plainText.getBytes("UTF-8"))); + } + + /** + * AES 고정 키 복호화 + */ + public static String decryptQuickAES(String cipherText) throws Exception { + Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); + cipher.init(Cipher.DECRYPT_MODE, FIXED_SECRET_KEY); + return new String( + cipher.doFinal(Base64.getDecoder().decode(cipherText)), + "UTF-8" + ); + } } diff --git a/src/main/resources/egovframework/egovProps/globals.properties.sample b/src/main/resources/egovframework/egovProps/globals.properties.sample index f09b90e1..49734508 100644 --- a/src/main/resources/egovframework/egovProps/globals.properties.sample +++ b/src/main/resources/egovframework/egovProps/globals.properties.sample @@ -37,4 +37,9 @@ JWT.secret_key=RnrxhWlQksportalSystem!@!@$#@!@#@!$12442321 # The token expires in 1,800,000 milliseconds, which is equal to 30 minutes. JWT.access_expired=1800000 O2MAP.wms.url=http://10.dbnt.co.kr:2936/o2map/services/wms -LOCAL.wms.url=http://10.dbnt.co.kr:2936/o2map/services/wms \ No newline at end of file +LOCAL.wms.url=http://10.dbnt.co.kr:2936/o2map/services/wms + +############################################### +################### SHA256 ################# +############################################### +SHA256.secret_key=RnrxhwlQksportalSystem!@34$% \ No newline at end of file