|
|
@@ -24,6 +24,57 @@ public class CryptoUtils {
|
|
|
private static final String AES_KEY = "dPtm24dnpqtjqltmdkaghsmsqlalf!@#";
|
|
|
private static final byte[] IV_BYTES = new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
|
|
|
|
|
+ /**
|
|
|
+ * YES24용 AES 암호화 처리
|
|
|
+ * @param rawValue - 원시문자열
|
|
|
+ * @return String - 암호화문자열
|
|
|
+ */
|
|
|
+ public static String encryptAES(String rawValue) {
|
|
|
+ String encryptedValue = "";
|
|
|
+
|
|
|
+ try {
|
|
|
+ if (StringUtils.isNotBlank(rawValue)) {
|
|
|
+ byte[] keyBytes = AES_KEY.getBytes("UTF-8");
|
|
|
+ SecretKeySpec keySpec = new SecretKeySpec(keyBytes, "AES");
|
|
|
+ Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
|
|
+ cipher.init(Cipher.ENCRYPT_MODE, keySpec, new IvParameterSpec(IV_BYTES));
|
|
|
+ encryptedValue = Base64.encodeBase64String(cipher.doFinal(rawValue.getBytes("UTF-8")));
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ //log.error(e.getMessage());
|
|
|
+ encryptedValue = rawValue;
|
|
|
+ }
|
|
|
+
|
|
|
+ return encryptedValue;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * YES24 연동용 AES 복호화 처리
|
|
|
+ * @param encryptedValue - 암호화된 문자열
|
|
|
+ * @return String - 복호화문자열
|
|
|
+ */
|
|
|
+ public static String decryptAES(String encryptedValue) {
|
|
|
+ String decryptedValue = "";
|
|
|
+
|
|
|
+ try {
|
|
|
+ if (StringUtils.isNotBlank(encryptedValue)) {
|
|
|
+ byte[] keyBytes = AES_KEY.getBytes("UTF-8");
|
|
|
+ SecretKeySpec keySpec = new SecretKeySpec(keyBytes, "AES");
|
|
|
+ Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
|
|
+ cipher.init(Cipher.DECRYPT_MODE, keySpec, new IvParameterSpec(IV_BYTES));
|
|
|
+ decryptedValue = new String(cipher.doFinal(Base64.decodeBase64(encryptedValue.getBytes("UTF-8"))), "UTF-8");
|
|
|
+ if (StringUtils.isBlank(decryptedValue)) {
|
|
|
+ decryptedValue = encryptedValue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ //log.error(e.getMessage());
|
|
|
+ decryptedValue = encryptedValue;
|
|
|
+ }
|
|
|
+
|
|
|
+ return decryptedValue;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* YES24용 AES 암호화 처리
|
|
|
* @param rawValue - 원시문자열
|
|
|
@@ -75,6 +126,7 @@ public class CryptoUtils {
|
|
|
return decryptedValue;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* JAVA에서는 AES키는 16byte이지만, MySQL에서는 16byte 이상도 지원하기에 MySQL의 16byte 이상의 키를 생성해야 한다.
|
|
|
* 16byte 이상은 잘라서 다시 앞쪽부터 byte 단위로 XOR 시켜서 16byte 키로 생성
|
|
|
@@ -100,7 +152,7 @@ public class CryptoUtils {
|
|
|
* @param rawValue - 원시문자열
|
|
|
* @return String - 암호화문자열
|
|
|
*/
|
|
|
- public static String encryptAES(String rawValue) {
|
|
|
+ public static String newEncryptAES(String rawValue) {
|
|
|
String encryptedValue = "";
|
|
|
|
|
|
try {
|
|
|
@@ -121,7 +173,7 @@ public class CryptoUtils {
|
|
|
* @param encryptedValue - 암호화된 문자열
|
|
|
* @return String - 복호화문자열
|
|
|
*/
|
|
|
- public static String decryptAES(String encryptedValue) {
|
|
|
+ public static String newDecryptAES(String encryptedValue) {
|
|
|
String decryptedValue = "";
|
|
|
|
|
|
try {
|