SQlCipher Android DataBase

public void trasferisco() {
try {
net.sqlcipher.database.SQLiteDatabase dab;
SQLiteDatabase.loadLibs(this);
String passphrase=“649121”;
File originalFile = getDatabasePath(DB_PATH+DB_NAME);
File newFile = File.createTempFile(“sqlcipherutils”, “tmp”, getCacheDir());
SQLiteDatabase existing_db = SQLiteDatabase.openDatabase(DB_PATH + DB_NAME, “”, null, SQLiteDatabase.OPEN_READWRITE);
existing_db.rawExecSQL(“ATTACH DATABASE '” + newFile.getPath() + “’ AS encrypted KEY '” + passphrase + “’;”);
existing_db.rawExecSQL(“SELECT sqlcipher_export(‘encrypted’);”);
existing_db.rawExecSQL(“DETACH DATABASE encrypted;”);
existing_db.close();
originalFile.delete();
newFile.renameTo(originalFile);;
} catch (Exception e) {
Log.e("error ", e.getMessage());
}

Error:

net.sqlcipher.database.sqliteexception error code 14 could not open database

[quote=“Marchesotti, post:21, topic:4905, full:true”]
public void trasferisco() {
try {
net.sqlcipher.database.SQLiteDatabase dab;
SQLiteDatabase.loadLibs(this);
String passphrase=“649121”;
File originalFile = getDatabasePath(DB_PATH+DB_NAME);
File newFile = File.createTempFile(“sqlcipherutils”, “tmp”, getCacheDir());
SQLiteDatabase existing_db = SQLiteDatabase.openDatabase(DB_PATH + DB_NAME, “”, null, SQLiteDatabase.OPEN_READWRITE);
existing_db.rawExecSQL(“ATTACH DATABASE '” + newFile.getPath() + “’ AS encrypted KEY '” + passphrase + “’;”);
existing_db.rawExecSQL(“SELECT sqlcipher_export(‘encrypted’);”);
existing_db.rawExecSQL(“DETACH DATABASE encrypted;”);
existing_db.close();
originalFile.delete();
newFile.renameTo(originalFile);;
} catch (Exception e) {
Log.e("error ", e.getMessage());
}public void trasferisco() {
try {
net.sqlcipher.database.SQLiteDatabase dab;
SQLiteDatabase.loadLibs(this);
String passphrase=“649121”;
File originalFile = getDatabasePath(DB_PATH+DB_NAME);
File newFile = File.createTempFile(“sqlcipherutils”, “tmp”, getCacheDir());
SQLiteDatabase existing_db = SQLiteDatabase.openDatabase(DB_PATH + DB_NAME, “”, null, SQLiteDatabase.OPEN_READWRITE);
existing_db.rawExecSQL(“ATTACH DATABASE '” + newFile.getPath() + “’ AS encrypted KEY '” + passphrase + “’;”);
existing_db.rawExecSQL(“SELECT sqlcipher_export(‘encrypted’);”);
existing_db.rawExecSQL(“DETACH DATABASE encrypted;”);
existing_db.close();
originalFile.delete();
newFile.renameTo(originalFile);;
} catch (Exception e) {
Log.e("error ", e.getMessage());
}

Error:

net.sqlcipher.database.sqliteexception error code 14 could not open database

Hello @Marchesotti

What exact line do you receive the error on? Can you fork the SQLCipher for Android test suite and try running that scenario within the suite? Instructions for creating a new test can be found here.

SecureRandom blocks the SQLCipherTest program

if(behaviorSuite != null){
behaviorSuite.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(TestRunnerSelectionActivity.this,
net.zetetic.tests.ImportUnencryptedDatabaseTest.class);
startActivity(intent);
}
});
}

i would like to use to convert Database to sqlcipher Database but i can’t start ImportUnencrytedDatabaseTest
Thank you

Hi @Marchesotti

The ImportUnencryptedDatabaseTest test is part of the suite which will run on a device/emulator. You don’t need to write specific code to invoke that test, it is already integrated within the suite. If you are receiving an error when running the suite, please post the full error. Without additional information, it is difficult to troubleshoot the issue you are experiencing.

the program does not start, gives no error, I tried to create a new program using;
ImportUnencrypteDatabaseTest, ISupportTest, NativeInitializer, TestResult, ZeteticApplication.
I use MainActivity to start the application.
Click Button to start ImportUnencrypteDatabaseTest and the program crashes and does not start the application

r1=findViewById(R.id.start);
r1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent avvio= new Intent(MainActivity.this, ImportUnencryptedDatabaseTest.class);
startActivity(avvio);
}
});

Thank you

Hi @Marchesotti

You will need to load this application within Android Studio, compile it, the deploy to either a device or emulator. You will see a lot of output via logcat in Android Studio.

SQLCipher Test Suite works, but I would like to use ImportUnencryptedDatabaseTest to copy my Database to enter password.
Run Test gives me error: Encrypt Bytes Test

Passed : 100 Failed : 1

my database is in /sdcard/Mkp/Archvio.db, but I can’t open with ImportUnencryptedDatabaseTest.jav
thank you

I managed to create encrypted database, everything works, I just can’t manage Cursor
How can I do?
Thank you

SQLcipher for C # examples exist