Skip to content

create sqlcipher database on sd-card #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gseebacher opened this issue Sep 30, 2012 · 5 comments
Closed

create sqlcipher database on sd-card #67

gseebacher opened this issue Sep 30, 2012 · 5 comments

Comments

@gseebacher
Copy link

hi,
i'm using openhelper to create sqlite databases. now i want to move to sqlcipher to encrypt my databases.
when i try to create a database on the sd-card i get an error "sqlite returned: error code = 14, msg = cannot open file at line ..."
creation of internal db works fine.
i have added the WRITE_EXTERNAL_STORAGE - permission to the manifest file.

seems that the onCreate does not get fired.
do you have any idea what is going wrong?
thanks in advance.

@developernotes
Copy link
Member

Hi gseebacher,

Are you using SQLiteDatabase.openOrCreateDatabase(...);? What path are you using? Also, have you checked to see if your SD Card is mounted?

@gseebacher
Copy link
Author

hi Nick,

thank you very much for your response. in the meantime i managed to get it
working. :-)
do you know by chance if the encryption libraries also work when i want to
create a encrypted sqlite db in windows using jdeveloper?

thanks, ciao
gerhard

2012/11/19 Nick Parker [email protected]

Hi gseebacher,

Are you using SQLiteDatabase.openOrCreateDatabase(...);? What path are
you using? Also, have you checked to see if your SD Card is mounted?


Reply to this email directly or view it on GitHubhttps://github.com//issues/67#issuecomment-10518448.

@developernotes
Copy link
Member

Hi gseebacher,

The SQLCipher for Android binaries require the Android runtime to exist, even with the new x86 build of the binaries. So this is not something that would work.

@gseebacher
Copy link
Author

thanks Nick!

2012/11/19 Nick Parker [email protected]

Hi gseebacher,

The SQLCipher for Android binaries require the Android runtime to exist,
even with the new x86 build of the binaries. So this is not something that
would work.


Reply to this email directly or view it on GitHubhttps://github.com//issues/67#issuecomment-10526323.

@pligor
Copy link

pligor commented Sep 23, 2013

Let me share a solution that worked for all android versions and is based upon this stackoverflow answer: http://stackoverflow.com/a/9168969/720484

Written in Scala:

/**
 * Useful to save the database in SD card
 * @param absoluteDirectoryPath the directory under which an sqlite database will be created
 */
class DatabaseContext(val absoluteDirectoryPath: String,
                      val password: String)(implicit val context: Context) extends ContextWrapper(context) {
  private val dbExtension = Some(".db");

  override def getDatabasePath(name: String): File = {
    val dbPath: String = absoluteDirectoryPath + File.separator + {
      if (dbExtension.isDefined && !name.endsWith(dbExtension.get)) name + dbExtension.get;
      else name;
    };

    val result = new File(dbPath);

    val parentFile = result.getParentFile;
    if (parentFile.exists) {
      //nop
    } else {
      parentFile.mkdirs;
    }

    result;
  }

  /*override def openOrCreateDatabase(name: String, mode: Int, factory: CursorFactory) = {
    //if something wrong with the database consider setting the factory argument to null in the line below
    SQLiteDatabase.openOrCreateDatabase(getDatabasePath(name), password, factory);
  }*/
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants