SQLCipher for React Native

Enterprise Edition Feature

SQLCipher for React Native provides full database encryption for cross-platform React Native applications targeting iOS, Android, and Windows. This SQLCipher package provides an officially supported way to quickly and easy integrate SQLCipher's AES-256 full database encryption into React Native apps. The API is based on and generally compatible with the popular `react-native-sqlite-storage` package. Plus it is fully interoperable with other SQLCipher platform libraries, and no special knowledge of cryptography is required. Let SQLCipher take care of data security behind the scenes with a small footprint and great performance.

Support for React Native is available only with the Enterprise Edition of SQLCipher.

Contact Us about SQLCipher for React Native

Initialize database connection:

class AppDatabase {

  db: SQLiteDatabase | null;
  promiseEnabled = false;
  dbName: string = "test.db";
  args = {
    name: this.dbName,
    dblocation: "default",
    license: "YOUR LICENSE CODE GOES HERE",
    password: "secure-key-material",
    preKey: [],
    postKey: [],
    readOnly: false,
  };

  constructor(){
    DEBUG(true);
  }

  public async openDatabaseConnectionPromise() {
    console.log("Entered openDatabaseConnectionPromise");
    let openArgs = Object.assign({}, this.args);
    this.db = await openDatabase(openArgs).catch(e => {
      console.error("Failed to open database connection: " + e);
    });
    // or
    // await openDatabase(openArgs)
    // .then( value => {
    //   this.db = value;
    //   console.log("[SUCCESS] Database opened");
    // })
    // .catch(e => {
    //   console.error("Failed to open database connection: " + e);
    // });
  }

Create a table and insert data:

    // Create table (if neccessary) and insert data in transaction
    result = new TestResult("Create table/insert data in transaction");
    await this.db.transaction((tx) => {

      tx.executeSql("CREATE TABLE IF NOT EXISTS t1(a,b);", [])
      .then((args) => {
        let msg = "Created t1 table if needed";
        console.log(msg);
        result.logSuccess(msg);
      }).catch(e => {
        var msg = "An error occurred creating t1: " + e;
        console.error(msg);
        result.logError(msg);
      });

      tx.executeSql("INSERT INTO t1(a,b) VALUES(?,?);", [1, 2])
      .then((args) => {
        let message = "Inserted into t1 table";
        console.log(message);
        result.logSuccess(message);
      }).catch(e => {
        var msg = "An error occurred inserting into t1: " + e;
        console.error(msg)
        result.logError(msg);
      });
    });
    values.push(result);

Executing a query:

   // // Query all rows from t1
    result = new TestResult("Query all rows from t1");
    var results = await this.db.executeSql("SELECT * from t1 order by rowid;", []);
    if(results != null){
      var rowResult = results;
      var rowResults: string[] = [];
      var rows = rowResult.rows.length;
      for(var row = 0; row < rows; row++){
        var a = rowResult.rows.item(row).a;
        var b = rowResult.rows.item(row).b;
        rowResults.push(`a:${a}, b:${b}`);
      }
      result.logSuccess(...rowResults);
    }
    values.push(result);

Contact Us about SQLCipher for React Native