safedb 디버깅
This commit is contained in:
@@ -13,7 +13,7 @@ public abstract class SafeDBFaker {
|
|||||||
private static final String AES_256_KEY = "1234567890123456" + "1234567890123456";
|
private static final String AES_256_KEY = "1234567890123456" + "1234567890123456";
|
||||||
|
|
||||||
|
|
||||||
public byte[] encrypt(String userId, String table, String column, String data) {
|
public byte[] encrypt(String userId, String table, String column, byte[] data) {
|
||||||
if (SafeDBColumns.PSWD.isEqualsIgnoreCase(column)) {
|
if (SafeDBColumns.PSWD.isEqualsIgnoreCase(column)) {
|
||||||
// SHA256 + Base64 인코딩된 가짜 비밀번호 반환
|
// SHA256 + Base64 인코딩된 가짜 비밀번호 반환
|
||||||
return sha256(data);
|
return sha256(data);
|
||||||
@@ -34,34 +34,34 @@ public abstract class SafeDBFaker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] sha256(String data) {
|
private byte[] sha256(byte[] data) {
|
||||||
MessageDigest digest = null;
|
MessageDigest digest = null;
|
||||||
try {
|
try {
|
||||||
digest = MessageDigest.getInstance("SHA-256");
|
digest = MessageDigest.getInstance("SHA-256");
|
||||||
return digest.digest(data.getBytes());
|
return digest.digest(data);
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
throw new RuntimeException("Error generating SHA-256 hash", e);
|
throw new RuntimeException("Error generating SHA-256 hash", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String sha256Base64(String data) {
|
private String sha256Base64(String data) {
|
||||||
return Base64.getEncoder().encodeToString(this.sha256(data));
|
return Base64.getEncoder().encodeToString(this.sha256(data.getBytes()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// AES256 암호화
|
// AES256 암호화
|
||||||
private byte[] aes256Encrypt(String data) {
|
private byte[] aes256Encrypt(byte[] data) {
|
||||||
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.ENCRYPT_MODE, keySpec);
|
cipher.init(javax.crypto.Cipher.ENCRYPT_MODE, keySpec);
|
||||||
return cipher.doFinal(data.getBytes());
|
return cipher.doFinal(data);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("Error during AES encryption", e);
|
throw new RuntimeException("Error during AES encryption", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getAes256KeyString(String data) {
|
private String getAes256KeyString(String data) {
|
||||||
return Base64.getEncoder().encodeToString(this.aes256Encrypt(data));
|
return Base64.getEncoder().encodeToString(this.aes256Encrypt(data.getBytes()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] aes256Decrypt(String encryptedData) {
|
private byte[] aes256Decrypt(String encryptedData) {
|
||||||
@@ -75,4 +75,8 @@ public abstract class SafeDBFaker {
|
|||||||
throw new RuntimeException("Error during AES decryption", e);
|
throw new RuntimeException("Error during AES decryption", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String encryptString(String safedb, String s, String notRnno, String data) {
|
||||||
|
return new String(this.encrypt(safedb, s, notRnno, data.getBytes()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,11 +86,11 @@ public class SafeDBWrapper extends SafeDBBroker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public byte[] encrypt(String userId, String table, String column, String data) throws SafeDBWrapperSdkException {
|
public byte[] encrypt(String userId, String table, String column, byte[] data) throws SafeDBWrapperSdkException {
|
||||||
if (isRealSafeDB) {
|
if (isRealSafeDB) {
|
||||||
try {
|
try {
|
||||||
log.debug("[SafeDBWrapper] real / userId : {}, table : {}, column : {}, data : {}", userId, table, column, data);
|
log.debug("[SafeDBWrapper] real / userId : {}, table : {}, column : {}, data : {}", userId, table, column, data);
|
||||||
return safedb.encrypt(userId, table, column, data.getBytes());
|
return safedb.encrypt(userId, table, column, data);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new SafeDBWrapperSdkException("[SafeDBWrapper] Encrypt error: " + e.getMessage(), e);
|
throw new SafeDBWrapperSdkException("[SafeDBWrapper] Encrypt error: " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
@@ -99,8 +99,20 @@ public class SafeDBWrapper extends SafeDBBroker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String encryptString(String userId, String tables, String column, String data) {
|
||||||
|
if (isRealSafeDB) {
|
||||||
|
try {
|
||||||
|
return this.safedb.encryptString(userId, tables, column, data);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new SafeDBWrapperSdkException("[SafeDBWrapper] Encrypt error: " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return this.encryptString(userId, tables, column, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String encryptNotRnnoString(String data) throws SafeDBWrapperSdkException {
|
public String encryptNotRnnoString(String data) throws SafeDBWrapperSdkException {
|
||||||
return new String(this.encrypt("SAFEDB", "SAFEDB.POLICY", "NOT_RNNO", data));
|
return this.encryptString("SAFEDB", "SAFEDB.POLICY", "NOT_RNNO", data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user