safedb 디버깅
This commit is contained in:
@@ -24,7 +24,7 @@ public abstract class SafeDBFaker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] decrypt(String userId, String table, String column, String data) {
|
public byte[] decrypt(String userId, String table, String column, byte[] data) {
|
||||||
if (SafeDBColumns.PSWD.isEqualsIgnoreCase(column)) {
|
if (SafeDBColumns.PSWD.isEqualsIgnoreCase(column)) {
|
||||||
// 비밀번호는 복호화하지 않음
|
// 비밀번호는 복호화하지 않음
|
||||||
throw new UnsupportedOperationException("Password decryption is not supported.");
|
throw new UnsupportedOperationException("Password decryption is not supported.");
|
||||||
@@ -64,13 +64,12 @@ public abstract class SafeDBFaker {
|
|||||||
return Base64.getEncoder().encodeToString(this.aes256Encrypt(data.getBytes()));
|
return Base64.getEncoder().encodeToString(this.aes256Encrypt(data.getBytes()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] aes256Decrypt(String encryptedData) {
|
private byte[] aes256Decrypt(byte[] encryptedData) {
|
||||||
try {
|
try {
|
||||||
Cipher cipher = javax.crypto.Cipher.getInstance("AES");
|
Cipher cipher = javax.crypto.Cipher.getInstance("AES");
|
||||||
SecretKeySpec keySpec = new javax.crypto.spec.SecretKeySpec(AES_256_KEY.getBytes(), "AES");
|
SecretKeySpec keySpec = new javax.crypto.spec.SecretKeySpec(AES_256_KEY.getBytes(), "AES");
|
||||||
cipher.init(javax.crypto.Cipher.DECRYPT_MODE, keySpec);
|
cipher.init(javax.crypto.Cipher.DECRYPT_MODE, keySpec);
|
||||||
byte[] decodedBytes = java.util.Base64.getDecoder().decode(encryptedData);
|
return cipher.doFinal(encryptedData);
|
||||||
return cipher.doFinal(decodedBytes);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("Error during AES decryption", e);
|
throw new RuntimeException("Error during AES decryption", e);
|
||||||
}
|
}
|
||||||
@@ -79,4 +78,8 @@ public abstract class SafeDBFaker {
|
|||||||
public String encryptString(String safedb, String s, String notRnno, String data) {
|
public String encryptString(String safedb, String s, String notRnno, String data) {
|
||||||
return new String(this.encrypt(safedb, s, notRnno, data.getBytes()));
|
return new String(this.encrypt(safedb, s, notRnno, data.getBytes()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String decryptString(String userId, String table, String column, String data) {
|
||||||
|
return new String(this.decrypt(userId, table, column, data.getBytes()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public class SafeDBWrapper extends SafeDBBroker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public byte[] encrypt(String userId, String table, String column, byte[] data) throws SafeDBWrapperSdkException {
|
public byte[] encrypt(String userId, String table, String column, byte[] data) throws SafeDBWrapperSdkException {
|
||||||
if (isRealSafeDB) {
|
if (isRealSafeDB) {
|
||||||
try {
|
try {
|
||||||
@@ -95,6 +95,7 @@ public class SafeDBWrapper extends SafeDBBroker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String encryptString(String userId, String tables, String column, String data) {
|
public String encryptString(String userId, String tables, String column, String data) {
|
||||||
if (isRealSafeDB) {
|
if (isRealSafeDB) {
|
||||||
try {
|
try {
|
||||||
@@ -111,14 +112,11 @@ public class SafeDBWrapper extends SafeDBBroker {
|
|||||||
return this.encryptString("SAFEDB", "SAFEDB.POLICY", "NOT_RNNO", data);
|
return this.encryptString("SAFEDB", "SAFEDB.POLICY", "NOT_RNNO", data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public byte[] decrypt(String userId, String table, String column, String data) throws SafeDBWrapperSdkException {
|
public byte[] decrypt(String userId, String table, String column, byte[] data) throws SafeDBWrapperSdkException {
|
||||||
if (isRealSafeDB) {
|
if (isRealSafeDB) {
|
||||||
try {
|
try {
|
||||||
log.debug("[SafeDBWrapper] String : {}", data);
|
return safedb.decrypt(userId, table, column, data);
|
||||||
byte[] dataBytes = Base64.getDecoder().decode(data);
|
|
||||||
log.debug("[SafeDBWrapper] Decode data : {}", dataBytes);
|
|
||||||
return safedb.decrypt(userId, table, column, dataBytes);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new SafeDBWrapperException("[SafeDBWrapper] Decrypt error: " + e.getMessage(), e);
|
throw new SafeDBWrapperException("[SafeDBWrapper] Decrypt error: " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
@@ -127,6 +125,18 @@ public class SafeDBWrapper extends SafeDBBroker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String decryptString(String userId, String table, String column, String data) throws SafeDBWrapperSdkException {
|
||||||
|
if (isRealSafeDB) {
|
||||||
|
try {
|
||||||
|
return safedb.decryptString(userId, table, column, data);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new SafeDBWrapperException("[SafeDBWrapper] Decrypt error: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return super.decryptString(userId, table, column, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String decryptNotRnno(String data) throws SafeDBWrapperSdkException {
|
public String decryptNotRnno(String data) throws SafeDBWrapperSdkException {
|
||||||
return new String(this.decrypt("SAFEDB", "SAFEDB.POLICY", "NOT_RNNO", data));
|
return new String(this.decrypt("SAFEDB", "SAFEDB.POLICY", "NOT_RNNO", data));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user