Hi All,
I see that there is a method in net.sqlcipher.database.SQLiteOpenHelper
changePassword(string)
. Is there any specific process to do this ? Meaning, I tried this method which ultimately threw
file is encrypted or is not a database
when using onCreate(db) db object
or below error when using getWriteableDatabase(currentPassword)
net.sqlcipher.database.SQLiteException: unknown error
04-09 16:13:47.629: E/AndroidRuntime(23895): at net.sqlcipher.database.SQLiteDatabase.native_rekey(Native Method
)
Is this method intended to literally change the password of database at runtime ? Pls clarify
Hello @vinay_kumar
The changePassword(…)
function performs a native call to sqlite3_rekey
. Please note you must have successfully keyed the database prior to making this call. The documentation for the native call can be found here.
Thanks for that Nick…GOT IT WORKING
Hi guys, i have this snippet from tabnine AI. is below snippet working to change password of db ?
@Synchronized
fun changePassword(context: AppCompatActivity, dbPrefixName: String, previousPassword: String, newPassword: String) {
val factory = SupportOpenHelperFactory(previousPassword.toByteArray(StandardCharsets.UTF_8))
val id = DeviceInfo.cachedAndroidId
dbLocation =
FileManager(context).getAppFile("databases/${dbPrefixName}${id}" + (if (BuildConfig.DEBUG) ".sql" else "")).absolutePath
val database =
Room.databaseBuilder(context, DLRoomDatabase::class.java, dbLocation).openHelperFactory(factory).build()
database.query("PRAGMA rekey = '$newPassword';", emptyArray())
// finish activity
context.finishAffinity()
}
- Android room database
- SQLCipher android