# SQlCipher Android DataBase

**URL:** https://discuss.zetetic.net/t/sqlcipher-android-database/4905
**Category:** SQLCipher
**Created:** [April 7, 2021, 4:54pm UTC](https://discuss.zetetic.net/t/sqlcipher-android-database/4905 "2021-04-07T16:54:49Z")
**Posts on this page:** 12
**Page:** 2

<div class="post-metadata">

### Author: ![Marchesotti](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@Marchesotti](https://discuss.zetetic.net/u/Marchesotti)
#### Post date: [April 14, 2021, 7:54am UTC](https://discuss.zetetic.net/t/sqlcipher-android-database/4905/21 "2021-04-14T07:54:10Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Marchesotti](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@Marchesotti](https://discuss.zetetic.net/u/Marchesotti)
#### Post date: [April 14, 2021, 4:56pm UTC](https://discuss.zetetic.net/t/sqlcipher-android-database/4905/22 "2021-04-14T16:56:02Z")

</div>

[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

---

<div class="post-metadata">

### Author: ![developernotes](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/developernotes/32/1309_2.png) [@developernotes](https://discuss.zetetic.net/u/developernotes)
#### Post date: [April 16, 2021, 12:25pm UTC](https://discuss.zetetic.net/t/sqlcipher-android-database/4905/23 "2021-04-16T12:25:55Z")

</div>

Hello @Marchesotti

What exact line do you receive the error on? Can you fork the SQLCipher for Android [test suite](https://github.com/sqlcipher/sqlcipher-android-tests) and try running that scenario within the suite? Instructions for creating a new test can be found [here](https://github.com/sqlcipher/sqlcipher-android-tests#creating-a-new-test).

---

<div class="post-metadata">

### Author: ![Marchesotti](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@Marchesotti](https://discuss.zetetic.net/u/Marchesotti)
#### Post date: [April 17, 2021, 3:24pm UTC](https://discuss.zetetic.net/t/sqlcipher-android-database/4905/24 "2021-04-17T15:24:52Z")

</div>

SecureRandom blocks the SQLCipherTest program

---

<div class="post-metadata">

### Author: ![Marchesotti](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@Marchesotti](https://discuss.zetetic.net/u/Marchesotti)
#### Post date: [April 18, 2021, 9:56pm UTC](https://discuss.zetetic.net/t/sqlcipher-android-database/4905/25 "2021-04-18T21:56:50Z")

</div>

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

---

<div class="post-metadata">

### Author: ![developernotes](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/developernotes/32/1309_2.png) [@developernotes](https://discuss.zetetic.net/u/developernotes)
#### Post date: [April 19, 2021, 1:01pm UTC](https://discuss.zetetic.net/t/sqlcipher-android-database/4905/26 "2021-04-19T13:01:06Z")

</div>

Hi @Marchesotti

The [ImportUnencryptedDatabaseTest](https://github.com/sqlcipher/sqlcipher-android-tests/blob/master/app/src/main/java/net/zetetic/tests/ImportUnencryptedDatabaseTest.java) 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.

---

<div class="post-metadata">

### Author: ![Marchesotti](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@Marchesotti](https://discuss.zetetic.net/u/Marchesotti)
#### Post date: [April 19, 2021, 1:43pm UTC](https://discuss.zetetic.net/t/sqlcipher-android-database/4905/27 "2021-04-19T13:43:53Z")

</div>

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

---

<div class="post-metadata">

### Author: ![developernotes](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/developernotes/32/1309_2.png) [@developernotes](https://discuss.zetetic.net/u/developernotes)
#### Post date: [April 20, 2021, 12:37pm UTC](https://discuss.zetetic.net/t/sqlcipher-android-database/4905/28 "2021-04-20T12:37:12Z")

</div>

Hi @Marchesotti

> [@Marchesotti](#):
>
> the program does not start, gives no error

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](https://developer.android.com/studio/debug/am-logcat).

---

<div class="post-metadata">

### Author: ![Marchesotti](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@Marchesotti](https://discuss.zetetic.net/u/Marchesotti)
#### Post date: [April 20, 2021, 1:38pm UTC](https://discuss.zetetic.net/t/sqlcipher-android-database/4905/29 "2021-04-20T13:38:16Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Marchesotti](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@Marchesotti](https://discuss.zetetic.net/u/Marchesotti)
#### Post date: [April 21, 2021, 8:37am UTC](https://discuss.zetetic.net/t/sqlcipher-android-database/4905/30 "2021-04-21T08:37:24Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Marchesotti](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@Marchesotti](https://discuss.zetetic.net/u/Marchesotti)
#### Post date: [April 24, 2021, 7:01am UTC](https://discuss.zetetic.net/t/sqlcipher-android-database/4905/31 "2021-04-24T07:01:22Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Marchesotti](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@Marchesotti](https://discuss.zetetic.net/u/Marchesotti)
#### Post date: [May 14, 2021, 1:48pm UTC](https://discuss.zetetic.net/t/sqlcipher-android-database/4905/32 "2021-05-14T13:48:31Z")

</div>

SQLcipher for C # examples exist

[Previous page](https://discuss.zetetic.net/t/sqlcipher-android-database/4905.md?page=1)
