|
|
@@ -126,7 +126,6 @@ public class CryptoUtils {
|
|
|
return decryptedValue;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* JAVA에서는 AES키는 16byte이지만, MySQL에서는 16byte 이상도 지원하기에 MySQL의 16byte 이상의 키를 생성해야 한다.
|
|
|
* 16byte 이상은 잘라서 다시 앞쪽부터 byte 단위로 XOR 시켜서 16byte 키로 생성
|
|
|
@@ -156,7 +155,7 @@ public class CryptoUtils {
|
|
|
String encryptedValue = "";
|
|
|
|
|
|
try {
|
|
|
- if (StringUtils.isNotBlank(rawValue)) {
|
|
|
+ if (rawValue != null) {
|
|
|
final Cipher cipher = Cipher.getInstance("AES"); // Cipher.getInstance("AES/ECB/PKCS5Padding")와 같음. ECB 모드의 경우 cipher.init 시 IvParameterSpec을 넣음 안 된다.
|
|
|
cipher.init(Cipher.ENCRYPT_MODE, generateMysqlAESKey("UTF-8"));
|
|
|
encryptedValue = new String(Hex.encodeHex(cipher.doFinal(rawValue.getBytes("UTF-8")))).toUpperCase();
|
|
|
@@ -182,10 +181,10 @@ public class CryptoUtils {
|
|
|
if (StringUtils.isNotBlank(encryptedValue)) {
|
|
|
final Cipher cipher = Cipher.getInstance("AES"); // Cipher.getInstance("AES/ECB/PKCS5Padding")와 같음
|
|
|
cipher.init(Cipher.DECRYPT_MODE, generateMysqlAESKey("UTF-8"));
|
|
|
- decryptedValue = new String(cipher.doFinal(Hex.decodeHex(encryptedValue.toCharArray())),"UTF-8");
|
|
|
- if (StringUtils.isBlank(decryptedValue)) {
|
|
|
- decryptedValue = encryptedValue;
|
|
|
- }
|
|
|
+ decryptedValue = new String(cipher.doFinal(Hex.decodeHex(encryptedValue.toCharArray())), "UTF-8");
|
|
|
+// if (StringUtils.isBlank(decryptedValue)) {
|
|
|
+// decryptedValue = encryptedValue;
|
|
|
+// }
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
// log.error(e.getMessage());
|
|
|
@@ -195,14 +194,14 @@ public class CryptoUtils {
|
|
|
return decryptedValue;
|
|
|
}
|
|
|
|
|
|
-// public static void main(String[] args) throws Exception {
|
|
|
-// String txt = "테스트";
|
|
|
-// String encrypt = CryptoUtils.encryptAES(txt);
|
|
|
-// String decrypt = CryptoUtils.decryptAES(encrypt);
|
|
|
-//
|
|
|
-// log.info("평문 : {}", txt);
|
|
|
-// log.info("암호화 : {}", encrypt);
|
|
|
-// log.info("복호화 : {}", decrypt);
|
|
|
-// }
|
|
|
+ public static void main(String[] args) throws Exception {
|
|
|
+ String txt = "테스트";
|
|
|
+ String encrypt = CryptoUtils.encryptAES(txt);
|
|
|
+ String decrypt = CryptoUtils.decryptAES(encrypt);
|
|
|
+
|
|
|
+ log.info("평문 : {}", txt);
|
|
|
+ log.info("암호화 : {}", encrypt);
|
|
|
+ log.info("복호화 : {}", decrypt);
|
|
|
+ }
|
|
|
|
|
|
}
|