SQLCipher for JDBC

Enterprise Edition Feature

SQLCipher for JDBC provides full database encryption for Java SE and EE desktop or server applications. This library makes it quick and easy to integrate SQLCipher’s AES-256 full database encryption into any application. It is fully interoperable with other SQLCipher platform libraries. No special knowledge of cryptography is required. SQLCipher takes care of data security behind the scenes with a small footprint and great performance.

SQLCipher for JDBC is packaged as single jar file with embedded native libraries Windows (x86 & x64), macOS (x64), and Linux (x86 & x64). Because the package has no external dependences it can be deployed to any supported platforms without requiring special configuration or distirbution of native shared libraries.

Support for JDBC is available only through the SQLCipher Enterprise program.

To use the JDBC just add the sqlcipher-jdbc.jar to the Java application classpath so it becomes available to the JDBC Driver Manager. JDBC URLs are of the format jdbc:sqlite:filename.

SQLCipher for JDBC offers three ways provide the key material (e.g. password). Any of these three options can be selected for use with most JDBC client implementations, ORM wrappers, or configuration systems.

Option 1: Provided the key material as the third parameter to getConnection (leave username null)

    Connection conn = DriverManager.getConnection(url, null, key);

Option 2: Provide key material as the password in a configuration Properties collection

    Properties props = new Properties();
    props.setProperty("password", key);
    Connection conn = DriverManager.getConnection(url, props);

Option 3: Provide key material with the standard SQCipher API using PRAGMA key

    try (Statement stmt = conn.createStatement();) {
      stmt.executeUpdate(String.format("PRAGMA key = '%s';", key));
    }

Once a JDBC connection is open the SQLCipher License Code can be provided using PRAGMA cipher_license;

    try (Statement stmt = conn.createStatement();) {
      stmt.executeUpdate(String.format("PRAGMA cipher_license = '%s';", licenseKey));
    }

Finally, the JDBC connection can be used to execute standard SQL statements on the encrypted database, e.g.

    try (
      Statement stmt = conn.createStatement();
    ) {
       stmt.execute("create table t1 (a);");
       stmt.execute("insert into t1 (a) values (1);");
    }

or

    try (
      Statement stmt = conn.createStatement();
      ResultSet rs = stmt.executeQuery("select a from t1;");
    ) {
       rs.next();
       String result = rs.getString(1);
    }

Contact Us about SQLCipher for JDBC