标签: sqlcipher-android

Android无法使用greendao使用sqlcipher加密数据库

我正在使用greendao ORM.我正在尝试使用SQLCipher加密我的数据库.Greendao自动支持sqlcipher.所以我写了以下加密代码.

 DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(context, "encrypted-db",null);

        Database db = helper.getEncryptedWritableDb("mySecretPassword");
        DaoSession session = new DaoMaster(db).newSession();
        return session;
Run Code Online (Sandbox Code Playgroud)

但是,每当我使用此会话执行任何数据库操作时,都会出错

 Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/greenrobot/greendao/database/DatabaseOpenHelper$EncryptedHelper;
                                                                       at org.greenrobot.greendao.database.DatabaseOpenHelper.checkEncryptedHelper(DatabaseOpenHelper.java:121)
                                                                       at org.greenrobot.greendao.database.DatabaseOpenHelper.getEncryptedWritableDb(DatabaseOpenHelper.java:133)
Run Code Online (Sandbox Code Playgroud)

我的gradle依赖是 - >

compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.2.0'
    compile 'org.greenrobot:greendao:3.2.0'
    compile 'com.google.code.gson:gson:2.8.0'
Run Code Online (Sandbox Code Playgroud)

我的计划是

-keepclassmembers class * extends org.greenrobot.greendao.AbstractDao {
public static java.lang.String TABLENAME;
}
-keep class **$Properties
# If you do not use Rx:
-dontwarn rx.**
Run Code Online (Sandbox Code Playgroud)

那么如何使用greendao和SQLCipher加密我的数据库?

PS:Database db = helper.getEncryptedWritableDb("mySecretPassword"); 此行在执行任何数据库操作时生成错误.

 Database db …
Run Code Online (Sandbox Code Playgroud)

android sqlcipher greendao sqlcipher-android greendao3

9
推荐指数
1
解决办法
796
查看次数

如何在本地存储SQLcipher密码

我正在使用一个使用SQLcipher并且它处于脱机状态的应用程序,所以我无法从服务器获取密钥以与加密数据库进行通信.我必须将其安全地存储在设备中的某个位置.一种解决方案是优先存储密钥,但如果手机已植根,则可以访问这些文件夹.应用程序中使用的数据是高度机密的,我不能让它被访问.如果你推荐对这种情况进行排序的话会很棒.提前致谢.

sqlite encryption android sqlcipher-android

7
推荐指数
1
解决办法
337
查看次数

如何在Android中保护我的加密密钥?

SQLCipher在我的Android应用程序中实现了它的数据库安全性.SQLCipher需要一个密钥来加密数据库文件.我面临的问题是密钥保护,如果我的应用程序在root设备上使用或者是逆向工程,那么我的密钥将被公开并且数据库可以被解密.

请注意,每次用户打开密码时我的应用程序都不会要求输入密码,因此用户输入的密码不能用作密钥.我想实现像facebook,whatsapp应用程序这样的行为,它使用私钥/密钥加密数据而不需要任何密码并让用户始终保持登录状态.这些应用程序在何处以及如何存储密钥?

请建议一个能够保护密钥的解决方案/算法.此外,Android OS是否提供任何此类功能以进行数据保护/管理?

android public-key-encryption sqlcipher-android

7
推荐指数
1
解决办法
836
查看次数

Android 发布崩溃并出现异常 net.sqlcipher.database.SQLiteException

我已将我的应用程序上传到 Play 商店,但它仍然崩溃,如开发人员控制台的“崩溃报告图像”所示。

在某些设备上,该应用程序根本不运行

而在其他情况下,它在启动 sql 查询时崩溃

顺便说一句,混淆器被禁用

崩溃报告图像 崩溃报告图像

查询方法 询问

android proguard crash-reports sqlcipher-android release-apk

7
推荐指数
1
解决办法
240
查看次数

使用 SQLCipher 后,我的 SQLite 数据库是否受到保护?

我已经用 SQLiteOpenHelper 替换了 import net.sqlcipher.database.SQLiteOpenHelper

为了将数据插入数据库并从中获取数据,我使用了
SQLiteDatabase db = this.getWritableDatabase("mypassword");

而不是下面

SQLiteDatabase db = this.getWritableDatabase();

下面是我的 oncreate 和 onUpgrade,

@Override
    public void onCreate(net.sqlcipher.database.SQLiteDatabase db) {

        db.execSQL(ARecords.CREATE_TABLE);
        db.execSQL(BRecords.CREATE_TABLE);
    }

    @Override
    public void onUpgrade(net.sqlcipher.database.SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop older table if existed
        db.execSQL("DROP TABLE IF EXISTS " + ARecords.TABLE_NAME);
        db.execSQL("DROP TABLE IF EXISTS " + BRecords.TABLE_NAME);
        //Create tables again
        onCreate(db);

    }
Run Code Online (Sandbox Code Playgroud)

在主活动中,

SQLiteDatabase.loadLibs(this);
Run Code Online (Sandbox Code Playgroud)

下面是我的依赖项

implementation 'net.zetetic:android-database-sqlcipher:4.4.3'
    implementation 'androidx.sqlite:sqlite:2.1.0'
Run Code Online (Sandbox Code Playgroud)

我正在使用 SQLCipher 来防止我的应用程序被攻击者访问存储在 /data/data/com.applicationname/ 目录中的数据

Root 设备可以访问 data/data/com.applicationname/ 目录的权限。那么使用 SQLCipher …

database encryption android sqlcipher-android

6
推荐指数
1
解决办法
278
查看次数

在Android Studio项目中集成SQLCIPHER

我尝试在我的Android应用程序中集成SQLCipher,使用此链接以及一些堆栈溢出链接(但它们已过时且与官方文档不同).

正确遵循所有步骤,编码部分没有错误.但最后,当我构建项目时,我得到的错误消息是:

错误:(11,0)未找到Gradle DSL方法:'defaultConfig()'可能的原因:

  • 项目'android-database-sqlcipher-master1'可能正在使用不包含该方法的Gradle版本.打开Gradle包装文件
  • 构建文件可能缺少Gradle插件.应用Gradle插件
  • 任何人都可以帮我摆脱这个错误.

    database android sqlcipher android-activity sqlcipher-android

    5
    推荐指数
    1
    解决办法
    4808
    查看次数

    使用 SQLCipher 加密后无法压缩 Android SQLite 数据库

    我随我的应用程序一起提供了一个只读数据库,将它包含在 Assets/Database 目录中。所有数据都是事先预填充的。

    SQLCipher数据库集成并加密后,我注意到 APK 大小从25MB膨胀到 150MB。原因是SQLite db 文件不再被压缩。

    Android Studio 通常会压缩资源,但在 DB 文件被加密后,压缩文件似乎没有效果。我尝试在外面用常规的 Zip 和 7Zip 测试它并没有什么区别,压缩文件的大小与原始文件相同。

    未加密的数据库大约 130MB,压缩后仅占用 18MB,因为其中大部分是文本和字符串压缩得很好。压缩加密的 db 文件在大小上没有区别。

    通过服务器填充不是一个可行的选择,因为由于记录的数量,它需要永远。从服务器下载完整加密的 DB 文件是下一个选项,但对于 140MB 的文件,它仍然会太慢。

    需要找到一种方法来随应用程序一起发送加密数据库,同时仍将应用程序大小保持在合理的20-30MB

    有任何想法吗?

    谢谢。

    sqlite encryption android filesize sqlcipher-android

    5
    推荐指数
    1
    解决办法
    711
    查看次数

    文件已加密或不是数据库: ,编译时: select count(*) from sqlite_master;

    我有一个已经生产多年的应用程序。它附带标准 Sqlite DB。该应用程序的最新版本集成了 SqlCipher 3.5.6 库。

    新数据库中有一些额外的表,因此我在 onUpgrade 方法中创建了它们。

    我在我的应用程序对象中调用了以下方法。

    SQLiteDatabase.loadLibs(this);
    
    Run Code Online (Sandbox Code Playgroud)

    旧apk中的DB_VERSION是56,我在新apk中将其设置为57,因此应该调用onUpgrade。

    我从 onUpgrade 内部调用加密方法。

    @Override
            public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    
                Log.e(TAG, "++++++++++++++++++++++++++SQLiteOpenHelper onUpgrade old version = " + oldVersion + " new version = " + newVersion);
    
    if(oldVersion == 56){
    
                    String sqlToCreateWeeklySummary = String
                            .format("create table %s ( %s INTEGER primary key, %s TEXT, %s TEXT, %s TEXT, %s TEXT, %s TEXT, %s TEXT, %s TEXT)",
                                    TABLEWEEKLYSUMMARY, C_ID_WEEKLY_SUMMARY, C_WEEKLY_SUMMARY_STARTDATE,
                                    C_WEEKLY_SUMMARY_PLANNEDCALLS, C_WEEKLY_SUMMARY_NCR, C_WEEKLY_SUMMARY_QA, C_WEEKLY_SUMMARY_PLANNEDHOURS,
                                    C_WEEKLY_SUMMARY_ACTUALCALLS, C_WEEKLY_SUMMARY_ACTUALHOURS); …
    Run Code Online (Sandbox Code Playgroud)

    sqlite encryption android sqlcipher-android

    5
    推荐指数
    1
    解决办法
    8760
    查看次数

    net.sqlcipher.database.SQLiteException: file is not a database: ,编译时: select count(*) from sqlite_master

    错误这一行:

    mDataBase = SQLiteDatabase.openDatabase(dbPath, "123", null, SQLiteDatabase.NO_LOCALIZED_COLLATORS);
    
    Run Code Online (Sandbox Code Playgroud)

    打开数据库时。但怎么了?如何用密码打开数据库?谁能帮我?

    1. 我在 SQLITE Db 浏览器 > 文件 > 设置加密上设置密码
    2. 在android部分打开这个密码
    3. 打开时显示错误
    4. error : net.sqlcipher.database.SQLiteException: file is not a database: , while compiling: select count(*) from sqlite_master

    任何人都可以帮我解决它吗?提前致谢

    import android.content.Context;
    import android.database.SQLException;
    //import android.database.sqlite.SQLiteOpenHelper;
    import android.util.Log;
    import net.sqlcipher.database.SQLiteDatabase;
    import net.sqlcipher.database.SQLiteDatabase;
    import net.sqlcipher.database.SQLiteOpenHelper;
    import net.sqlcipher.database.SQLiteDatabase.CursorFactory;
    
    
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.io.File;
    import net.sqlcipher.database.SQLiteDatabase;
    import android.app.Activity;
    import android.os.Bundle;
    
    public class DatabaseHelper extends SQLiteOpenHelper {
    
        private static String TAG = DatabaseHelper.class.getName(); …
    Run Code Online (Sandbox Code Playgroud)

    sqlcipher sqliteopenhelper android-sqlite sqlcipher-android

    5
    推荐指数
    1
    解决办法
    5181
    查看次数

    从现有 Room 数据库迁移到 Sqlcipher

    我的应用程序目前正在使用房间数据库。我想迁移到使用 Sqlcipher 数据库。我已经fallbackToDestructiveMigration()启用但仍然抛出以下错误

    java.lang.RuntimeException: Exception while computing database live data.
        at androidx.room.RoomTrackingLiveData$1.run(RoomTrackingLiveData.java:92)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: net.sqlcipher.database.SQLiteException: file is not a database: , while compiling: select count(*) from sqlite_master;
        at net.sqlcipher.database.SQLiteCompiledSql.native_compile(Native Method)
        at net.sqlcipher.database.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)
        at net.sqlcipher.database.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64)
        at net.sqlcipher.database.SQLiteProgram.<init>(SQLiteProgram.java:91)
        at net.sqlcipher.database.SQLiteQuery.<init>(SQLiteQuery.java:48)
        at net.sqlcipher.database.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:60)
        at net.sqlcipher.database.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:2016)
        at net.sqlcipher.database.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1902)
        at net.sqlcipher.database.SQLiteDatabase.keyDatabase(SQLiteDatabase.java:2673)
        at net.sqlcipher.database.SQLiteDatabase.openDatabaseInternal(SQLiteDatabase.java:2603)
        at net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1247)
        at net.sqlcipher.database.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1322)
        at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:166)
        at net.sqlcipher.database.SupportHelper.getWritableDatabase(SupportHelper.java:83)
        at androidx.room.RoomDatabase.inTransaction(RoomDatabase.java:476)
        at androidx.room.RoomDatabase.assertNotSuspendingTransaction(RoomDatabase.java:281)
        at androidx.room.RoomDatabase.query(RoomDatabase.java:324)
        at androidx.room.util.DBUtil.query(DBUtil.java:83)
        at com.screenlocker.secure.room.MyDao_Impl$29.call(MyDao_Impl.java:1249)
        at com.screenlocker.secure.room.MyDao_Impl$29.call(MyDao_Impl.java:1246)
        at androidx.room.RoomTrackingLiveData$1.run(RoomTrackingLiveData.java:90)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) …
    Run Code Online (Sandbox Code Playgroud)

    android sqlcipher-android android-room

    5
    推荐指数
    2
    解决办法
    1459
    查看次数

    在 Android 应用程序中将 SqlCipher 与 ProGuard 一起使用时出现 NoSuchFieldError

    出于安全原因,要求之一是加密 SQLite 数据库。因此,我必须使用 SQLCupher。只要我不使用 启用混淆,应用程序就会按预期工作minifyEnabled true

    一旦我设置minifyEnabled true,我就会得到一个NoSuchFieldError.

    我正在 Application 子类中初始化 SQLCipher:

    SQLiteDatabase.loadLibs(this);
    
    Run Code Online (Sandbox Code Playgroud)

    这是异常日志:

    com.iconnectyo: runtime.cc:663] JNI DETECTED ERROR IN APPLICATION: JNI FindClass called with pending exception java.lang.NoSuchFieldError: no "J" field "mNativeHandle" in class "Lnet/sqlcipher/database/SQLiteDatabase;" or its superclasses
        runtime.cc:663]   at java.lang.String java.lang.Runtime.nativeLoad(java.lang.String, java.lang.ClassLoader, java.lang.Class) (Runtime.java:-2)
        runtime.cc:663]   at java.lang.String java.lang.Runtime.nativeLoad(java.lang.String, java.lang.ClassLoader) (Runtime.java:1131)
        runtime.cc:663]   at void java.lang.Runtime.loadLibrary0(java.lang.ClassLoader, java.lang.Class, java.lang.String) (Runtime.java:1085)
        runtime.cc:663]   at void java.lang.Runtime.loadLibrary0(java.lang.Class, java.lang.String) (Runtime.java:1008)
        runtime.cc:663]   at void java.lang.System.loadLibrary(java.lang.String) (System.java:1664)
        runtime.cc:663]   at void net.sqlcipher.database.SQLiteDatabase$a.a(java.lang.String[]) (:213) …
    Run Code Online (Sandbox Code Playgroud)

    android proguard sqlcipher sqlcipher-android

    3
    推荐指数
    1
    解决办法
    1966
    查看次数

    使用SQLCipher -Android将纯内容提供程序数据(由SQLite支持)升级为加密

    我正在尝试使用App升级来加密存储在我的内容提供商中的数据.我按照下面的链接,
    如何在使用SQLiteOpenHelper时实现SQLCipher

    如果完成新安装,这种方法完全正常,如果我进行升级,应用程序崩溃时会出现以下错误

        net.sqlcipher.database.SQLiteException: file is encrypted or is not a database
    at  android.app.ActivityThread.handleReceiver(ActivityThread.java:3009)
    at  android.app.ActivityThread.access$1800(ActivityThread.java:177)
    at  android.app.ActivityThread$H.handleMessage(ActivityThread.java:1526)
    at  android.os.Handler.dispatchMessage(Handler.java:102)
    at  android.os.Looper.loop(Looper.java:145)
    at  android.app.ActivityThread.main(ActivityThread.java:5951)
    at  java.lang.reflect.Method.invoke(Native Method)
    at  java.lang.reflect.Method.invoke(Method.java:372)
    at  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
    at  com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
        Caused by: net.sqlcipher.database.SQLiteException: file is encrypted or is not a database
    
    Run Code Online (Sandbox Code Playgroud)


    我甚至试图删除现有的表并创建一个新表,只是为了看看这是否解决了问题,但没有任何帮助.请建议如何解决这个问题,My Helper课程如下,

                    public class MyDBHelper extends SQLiteOpenHelper {
                    public MyDBHelper(Context context) {
                        super(context, DATABASE_NAME, null, DATABASE_VERSION);
                        SQLiteDatabase.loadLibs(context);
                    }
                    public static final String DATABASE_NAME = "mydb.db";
    
                    private static final int DATABASE_VERSION = 2; // before attempting encryption …
    Run Code Online (Sandbox Code Playgroud)

    android sqlcipher-android

    2
    推荐指数
    1
    解决办法
    571
    查看次数