diff options
Diffstat (limited to 'sql-resource')
-rw-r--r-- | sql-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResource.java | 101 |
1 files changed, 35 insertions, 66 deletions
diff --git a/sql-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResource.java b/sql-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResource.java index 78d92d09b..df3d8132d 100644 --- a/sql-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResource.java +++ b/sql-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResource.java @@ -382,72 +382,41 @@ public class SqlResource implements SvcLogicResource, SvcLogicJavaPlugin { return (executeSqlWrite(key, ctx)); } - private String decryptColumn(String tableName, String colName, byte[] colValue, DbLibService dblibSvc) { - String strValue = new String(colValue); - - if (StringUtils.isAsciiPrintable(strValue)) { - - // If printable, not encrypted - return (strValue); - } else { - PreparedStatement stmt = null; - Connection conn = null; - ResultSet results = null; - try { - // CachedRowSet results = - // dblibSvc.getData("SELECT - // CAST(AES_DECRYPT('"+strValue+"','"+CRYPT_KEY+"') AS CHAR(50)) - // FROM DUAL", - // null, null); - conn = ((DBResourceManager) dblibSvc).getConnection(); - - stmt = conn.prepareStatement("SELECT CAST(AES_DECRYPT(?, ?) AS CHAR(50)) FROM DUAL"); - - stmt.setBytes(1, colValue); - stmt.setString(2, getCryptKey()); - - results = stmt.executeQuery(); - - if ((results != null) && results.next()) { - strValue = results.getString(1); - LOG.debug("Decrypted value is " + strValue); - } else { - LOG.warn("Cannot decrypt " + tableName + "." + colName); - } - } catch (Exception e) { - LOG.error("Caught exception trying to decrypt " + tableName + "." + colName, e); - } finally { - try { - if (results != null) { - results.close(); - results = null; - } - } catch (Exception exc) { - - } - - try { - if (stmt != null) { - stmt.close(); - stmt = null; - } - } catch (Exception exc) { - - } - - try { - if (conn != null) { - conn.close(); - conn = null; - } - } catch (Exception exc) { - - } - - } - } - return (strValue); - } + private String decryptColumn(String tableName, String colName, byte[] colValue, DbLibService dblibSvc) { + String strValue = new String(colValue); + + if (StringUtils.isAsciiPrintable(strValue)) { + + // If printable, not encrypted + return (strValue); + } else { + ResultSet results = null; + try (Connection conn = ((DBResourceManager) dblibSvc).getConnection(); + PreparedStatement stmt = conn.prepareStatement("SELECT CAST(AES_DECRYPT(?, ?) AS CHAR(50)) FROM DUAL")) { + + stmt.setBytes(1, colValue); + stmt.setString(2, getCryptKey()); + results = stmt.executeQuery(); + + if ((results != null) && results.next()) { + strValue = results.getString(1); + LOG.debug("Decrypted value is " + strValue); + } else { + LOG.warn("Cannot decrypt " + tableName + "." + colName); + } + } catch (Exception e) { + if (results != null) { + try { + results.close(); + } catch (SQLException ignored) { + + } + } + LOG.error("Caught exception trying to decrypt " + tableName + "." + colName, e); + } + } + return (strValue); + } public static String getCryptKey() { return (CRYPT_KEY); |