Exemple #1
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            SQLite3Plugin.Init();
            SQLitePCL.ISQLite3Provider imp = new SQLitePCL.SQLite3Provider_sqlcipher();
            SQLitePCL.raw.SetProvider(imp);

            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.Filter = "UnEncrypted DB File|*.udb";
            saveFileDialog1.Title  = "Save UnEncrypted DB";
            saveFileDialog1.ShowDialog();
            if (saveFileDialog1.FileName == "")
            {
                return;
            }

            var db = new SQLiteConnection(saveFileDialog1.FileName);

            db.CreateTable <Test>();

            db.Insert(new Test()
            {
                TestText = DateTime.Now.ToString()
            });

            var query = db.Table <Test>();

            foreach (var test in query)
            {
                Console.WriteLine("Test: " + test.TestText);
            }
            db.Dispose();
        }
Exemple #2
0
        private void btnEncrypt_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter = "UnEncrypted DB File|*.udb";
            openFileDialog1.Title  = "Open UnEncrypted DB";
            openFileDialog1.ShowDialog();

            if (openFileDialog1.FileName == "")
            {
                return;
            }

            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.Filter = "Encrypted DB File|*.edb";
            saveFileDialog1.Title  = "Save Encrypted DB";
            saveFileDialog1.ShowDialog();
            if (saveFileDialog1.FileName == "")
            {
                return;
            }

            SQLite3Plugin.Init();
            SQLitePCL.ISQLite3Provider imp = new SQLitePCL.SQLite3Provider_sqlcipher();
            SQLitePCL.raw.SetProvider(imp);

            sqlite3 db;

            raw.sqlite3_open(openFileDialog1.FileName, out db);
            raw.sqlite3_exec(db, "ATTACH DATABASE '" + saveFileDialog1.FileName + "' AS encrypted KEY 'testkey';");
            raw.sqlite3_exec(db, "SELECT sqlcipher_export('encrypted');");
            raw.sqlite3_exec(db, "DETACH DATABASE encrypted;");
            db.Dispose();
        }
Exemple #3
0
        private void EncryptRead_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter = "Encrypted DB File|*.edb";
            openFileDialog1.Title  = "Open Encrypted DB";
            openFileDialog1.ShowDialog();

            if (openFileDialog1.FileName == "")
            {
                return;
            }

            SQLite3Plugin.Init();
            SQLitePCL.ISQLite3Provider imp = new SQLitePCL.SQLite3Provider_sqlcipher();
            SQLitePCL.raw.SetProvider(imp);
            var db = new SQLiteConnection(openFileDialog1.FileName);

            db.Execute("PRAGMA key = 'testkey';");
            var query = db.Table <Test>();

            foreach (var test in query)
            {
                MessageBox.Show(test.TestText);
            }
        }