SafeJDBC v2.00

com.safejdbc.api
Class CipherConnectionFactory

java.lang.Object
  extended by com.safejdbc.api.CipherConnectionFactory

public final class CipherConnectionFactory
extends Object

Factory to create a Cipher Connection -
A Cipher Connection is a Connection that enables the automatic encryption and decryption of SQL statements and results using and wrapping a native database Connection.

Because each Cipher Connection wraps a Connection, this mechanism allows safe connection pooling with SafeJDBC.

Note that it is much better and easier to manage connection pooling using the DataSource mechanism, such as in Tomcat 5.0 implementation. The SafeDataSourceFactory class is designed for this purpose and is documented in the SafeJDBC PDF User Documentation.

A Cipher Connection is built using 2 Java/JDBC Connections:

  1. A first Connection to the/your application database
  2. .
  3. A second Connection to the SafeJDBC Catalog database
  4. .
Prior to calling CipherConnectionFactory, some settings must be set using SafeJdbcSetter class or using an ini file:
  1. Setting all parameters so that SafeJDBC can get a Connection to the SafeJDBC Catalog.
  2. Set the SafeJDBC Userid & Key.
The following examples use SafeJDBC values in this con_safejdbc.ini file:

// This is the application database url
String sDbUrl = "jdbc:mysql://localhost:3306/sj_clients";

// These are the username & password for the application database
Properties propsApp = new Properties();
propsApp.put("user", "safelogic");
propsApp.put("password", "safelogic*$");

// Load the native Driver and get a normal Connection to the application database.
// Note: this could be done using the DataSource mechanism in a J2EE environment.
Class.forName("org.gjt.mm.mysql.Driver").newInstance();

// Get a Connection to the application database
Connection conApplication = DriverManager.getConnection(sDbUrl, propsApp);

// This is the SafeJdbc Catalog database url
String sSafeJdbcDbUrl = "jdbc:mysql://localhost:3306/safejdbc_catalog";

Properties propsSjdbc = new Properties();
propsSjdbc.put("user", "safelogic");
propsSjdbc.put("password", "safelogic*$");

// Get a Connection to the SafeJdbc Catalog database
Connection conSafeJdbcCatalog = DriverManager.getConnection(sSafeJdbcDbUrl, propsSjdbc);

// Get the Cipher Connection for the encryption of statements and results
Connection connection = CipherConnectionFactory.getInstance(conApplication, conSafeJdbcCatalog);

See Also:
SafeDataSourceFactory

Method Summary
static Connection getInstance(Connection conApplication)
          Deprecated. Please use createCipherConnection(Connection, Connection)
static Connection getInstance(Connection conApplication, Connection conSafeJdbcCatalog)
          Creates a Cipher Connection to eanble the automatic and transparent encryption and decryption of SQL statements and results.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static Connection getInstance(Connection conApplication)
                              throws SQLException
Deprecated. Please use createCipherConnection(Connection, Connection)

Creates a Cipher Connection to enable the automatic and transparent encryption and decryption of SQL statements and results.

The Cipher Connection to the application database uses/wraps the native application Connection.
The Cipher Connection factory automatically creates a Connection to the SafeJDBC Catalog database, using settings provided by SafeJdbcSetter or values in the con_safejdbc.ini file located in the Java CLASSPATH.
THIS METHOD IS DEFINITELY DEPRECATED AND WILL THROW AN EXCEPTION.

Parameters:
conApplication - the native application database Connection to be used.
Throws:
SQLException - if a SQL Exception occurs.

getInstance

public static Connection getInstance(Connection conApplication,
                                     Connection conSafeJdbcCatalog)
                              throws SQLException
Creates a Cipher Connection to eanble the automatic and transparent encryption and decryption of SQL statements and results.

The Cipher Connection uses/wraps the native application Connection to the application database.

A Cipher Connection is built using 2 Java/JDBC Connections:
  1. A first Connection to the/your application database.
  2. A second Connection to the SafeJDBC Catalog database.

This method can be safely used with 2 Connections from pools.
It does *not* load a Driver instance and does not create a new physical Connection to the database.

Parameters:
conApplication - the native application database Connection to be used.
conSafeJdbcCatalog - the SafeJdbc Catalog database Connection to be used.
Throws:
SQLException - if a SQL Exception occurs.

SafeJDBC v2.00

Copyright © SafeLogic 2011