net.sqlcipher.database.SQLiteException: not authorized: , while compiling: select count(*) from sqlite_master

SQLCipher version - 3.5.9, Android OS - Android 6.0

  • We are already loading the library using - SQLiteDatabase.loadLibs(context); at the start of the app before calling any database related api.

  • Database password is also plain text without any encryption.

While calling getWritableDatabase(getPassword()), sqlcipher is throwing following exception -

net.sqlcipher.database.SQLiteException: not authorized: , while compiling: select count(*) from sqlite_master;
                                                              at net.sqlcipher.database.SQLiteCompiledSql.native_compile(Native Method)
                                                              at net.sqlcipher.database.SQLiteCompiledSql.compile(
                                                              at net.sqlcipher.database.SQLiteCompiledSql.<init>(
                                                              at net.sqlcipher.database.SQLiteProgram.<init>(
                                                              at net.sqlcipher.database.SQLiteQuery.<init>(
                                                              at net.sqlcipher.database.SQLiteDirectCursorDriver.query(
                                                              at net.sqlcipher.database.SQLiteDatabase.rawQueryWithFactory(
                                                              at net.sqlcipher.database.SQLiteDatabase.rawQuery(
                                                              at net.sqlcipher.database.SQLiteDatabase.keyDatabase(
                                                              at net.sqlcipher.database.SQLiteDatabase.openDatabaseInternal(
                                                              at net.sqlcipher.database.SQLiteDatabase.openDatabase(
                                                              at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(
                                                              at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(
                                                              at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(
                                                              at com.cropin.smartfarm.core.db.DBHelper.getDb(

Hello @CropIn_Developer - You will receive a not authorized error if you are using SQLCipher Commercial Edition and your license key is invalid or has expired (i.e. if you are using a trial version and the trial period is over).

good afternoon

in android studio, in which section I have to enter the password they gave me.

PRAGMA cipher_license = trial license


You can apply it in either the preKey or postKey hook.

private void InitializeSQLCipher() {
    SQLiteDatabaseHook mHook = new SQLiteDatabaseHook() {
        public void preKey(SQLiteDatabase database) {
            // no-op

        public void postKey(SQLiteDatabase database) {
            database.rawExecSQL("PRAGMA cipher_license='YOUR_LICENSE';");
    File databaseFile = getDatabasePath("demo.db");
    SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(databaseFile, "B1GS3CR3T", null, mHook);
    database.execSQL("create table t1(a, b)");
    database.execSQL("insert into t1(a, b) values(?, ?)", new Object[]{"One for the Money",
            "Two For the Show"});
1 Like

good afternoon
I appreciate your support helped me too, I share how you implement it.

private static DBHelper instancia;
private static final int DB_version=1;
public static final String DB_name=“ppp.db”;
public static final String License_PHARSE = “my_License”;

public DBHelper(Context context,SQLiteDatabaseHook val) {

   super(context, DB_name, null, DB_version,val);

static public synchronized DBHelper getInstance(Context context){
    SQLiteDatabaseHook myh=new SQLiteDatabaseHook() {
        public void preKey(SQLiteDatabase sqLiteDatabase) {


        public void postKey(SQLiteDatabase sqLiteDatabase) {
            sqLiteDatabase.rawExecSQL("PRAGMA cipher_license='"+License_PHARSE+"'");
    if(instancia == null)
        instancia = new DBHelper(context,myh);
    return instancia;

use SQLiteOpenHelper

1 Like