안쓰는 파일 삭제
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
package app.module.core.config.application.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum UiCodeType {
|
||||
REGION_MAIN("code.region.main"),
|
||||
REGION_SUB("code.region.sub");
|
||||
private final String code;
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
package app.module.core.config.application.util;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.crypto.BadPaddingException;
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.IllegalBlockSizeException;
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Base64;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class AESEncryptUtil {
|
||||
|
||||
@Value("${aes.secret-key}")
|
||||
private String key;
|
||||
|
||||
@Value("${encrypt.aes.iv}")
|
||||
private String iv;
|
||||
|
||||
private static final String AES_ALGORITHM = "AES/CBC/PKCS5PADDING";
|
||||
public static final String ENCRYPT_IV = "0123456789ABCDEF";
|
||||
|
||||
public String encrypt(String text)
|
||||
throws NoSuchPaddingException, NoSuchAlgorithmException, BadPaddingException,
|
||||
IllegalBlockSizeException, InvalidAlgorithmParameterException, InvalidKeyException {
|
||||
Cipher cipher = Cipher.getInstance(getTransformation());
|
||||
SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "AES");
|
||||
IvParameterSpec ivParamSpec = new IvParameterSpec(iv.getBytes());
|
||||
cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivParamSpec);
|
||||
|
||||
byte[] encrypted = cipher.doFinal(text.getBytes(StandardCharsets.UTF_8));
|
||||
return Base64.getEncoder().encodeToString(encrypted);
|
||||
}
|
||||
|
||||
public String decrypt(String cipherText)
|
||||
throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException,
|
||||
InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
|
||||
Cipher cipher = Cipher.getInstance(getTransformation());
|
||||
SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "AES");
|
||||
IvParameterSpec ivParamSpec = new IvParameterSpec(iv.getBytes());
|
||||
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivParamSpec);
|
||||
|
||||
byte[] decodedBytes = Base64.getDecoder().decode(cipherText);
|
||||
byte[] decrypted = cipher.doFinal(decodedBytes);
|
||||
return new String(decrypted, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
|
||||
public byte[] encryptAesCbc(byte[] plainData) {
|
||||
if (plainData == null || plainData.length == 0) {
|
||||
throw new IllegalArgumentException("데이터는 null이거나 비어 있을 수 없습니다.");
|
||||
}
|
||||
|
||||
try {
|
||||
SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "AES");
|
||||
IvParameterSpec ivSpec = new IvParameterSpec(ENCRYPT_IV.getBytes(StandardCharsets.UTF_8));
|
||||
Cipher cipher = Cipher.getInstance(AES_ALGORITHM);
|
||||
cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec);
|
||||
return org.apache.commons.codec.binary.Base64.encodeBase64(cipher.doFinal(plainData));
|
||||
} catch (Exception e) {
|
||||
log.error("바이너리 데이터 암호화 실패", e);
|
||||
throw new RuntimeException("바이너리 데이터 암호화 실패", e);
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] decryptAesCbc(byte[] cipherData) {
|
||||
if (cipherData == null || cipherData.length == 0) {
|
||||
throw new IllegalArgumentException("암호문은 null이거나 비어 있을 수 없습니다.");
|
||||
}
|
||||
|
||||
try {
|
||||
byte[] encrypted = org.apache.commons.codec.binary.Base64.decodeBase64(cipherData);
|
||||
SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "AES");
|
||||
IvParameterSpec ivSpec = new IvParameterSpec(ENCRYPT_IV.getBytes(StandardCharsets.UTF_8));
|
||||
Cipher cipher = Cipher.getInstance(AES_ALGORITHM);
|
||||
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
|
||||
return cipher.doFinal(encrypted);
|
||||
} catch (Exception e) {
|
||||
log.error("바이너리 데이터 복호화 실패", e);
|
||||
throw new RuntimeException("바이너리 데이터 복호화 실패", e);
|
||||
}
|
||||
}
|
||||
|
||||
private String getTransformation() {
|
||||
return "AES/CBC/PKCS5Padding";
|
||||
}
|
||||
}
|
||||
@@ -126,41 +126,4 @@ public class CommonUtil {
|
||||
flashMessages.add(msg);
|
||||
session.setAttribute("flashAlertMessages", flashMessages);
|
||||
}
|
||||
|
||||
public static String normalizePath(String path) {
|
||||
if (path == null || path.trim().isEmpty()) {
|
||||
log.warn("normalizePath: Input path is null or empty, returning default path");
|
||||
String defaultPath = System.getProperty("user.home") + File.separator + "Downloads";
|
||||
return Paths.get(defaultPath).toAbsolutePath().normalize().toString();
|
||||
}
|
||||
|
||||
try {
|
||||
// Paths.get을 사용하여 경로 정규화
|
||||
Path normalizedPath = Paths.get(path).toAbsolutePath().normalize();
|
||||
String result = normalizedPath.toString();
|
||||
log.debug("Normalized path: {}", result);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.error("Error normalizing path: {}", path, e);
|
||||
throw new IllegalArgumentException("Failed to normalize path: " + path, e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void createDirectories(File directory) {
|
||||
if (directory == null) {
|
||||
throw new IllegalArgumentException("Directory cannot be null");
|
||||
}
|
||||
try {
|
||||
if (!directory.exists()) {
|
||||
boolean created = directory.mkdirs();
|
||||
log.info("Directory created: {} (Success: {})", directory.getAbsolutePath(), created);
|
||||
}
|
||||
if (!directory.canWrite()) {
|
||||
throw new IOException("No write permission for directory: " + directory.getAbsolutePath());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to create directory: {}", directory.getAbsolutePath(), e);
|
||||
throw new RuntimeException("Failed to create directory", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user