C # leverages SQLite to create databases for. DB and. LOGDB encryption and decryption and SQLite

Source: Internet
Author: User
Tags sqlite

1. Recently studied the use of SQLite as a DB file simple encryption and decryption

1  Private Staticsqliteconnection getconnection ()2         {3 Sqliteconnection Conn;4             stringPassword = Dataprovider.configsearch (Configcode.sys_file_encryption_password,true)[0]. Value;5             stringDBFile =Path.Combine (Environment.getfolderpath (Environment.SpecialFolder.CommonApplicationData), Configcode.client_ Data_path);6             stringDbPath =Path.getdirectoryname (dbfile);7             if(!directory.exists (dbPath))8             {9 directory.createdirectory (dbPath);Ten             } One             if(!file.exists (dbfile)) A             { -                 //database does not exist, create - Sqliteconnection.createfile (dbfile); the commonutils.setaccesscontrollist (dbfile); -conn =NewSqliteconnection (string. Format ("Data source={0}; Pooling=true; Failifmissing=false", DBFile)); - Conn. Open (); - Conn. ChangePassword (password); +                 if(string. IsNullOrEmpty (install_db_sql)) -                 { +Install_db_sql = Path.Combine (Path.getdirectoryname (typeof(Sqliteprovider). Assembly.location),"Setup.sql"); A                 } at  -                 foreach(stringLineinchFile.readalltext (Install_db_sql). Split (New Char[] {';' })) -                 { -                     if(String.IsNullOrEmpty (line)) -                     { -                         Continue; in                     } -Sqlitecommand cmd =Conn. CreateCommand (); toCmd.commandtext =Line ; +Cmd.commandtype =CommandType.Text; - cmd. ExecuteNonQuery (); the cmd. Dispose (); *                 } $             }Panax Notoginseng             Else -             { the                 Try +                 { Aconn =NewSqliteconnection (string. Format ("Data source={0}; Pooling=true; Failifmissing=false", DBFile)); the Conn. SetPassword (password); + Conn. Open (); - Conn. ChangePassword (password); $                 } $                 Catch(Exception) -                 { -conn =NewSqliteconnection (string. Format ("Data source={0}; Pooling=true; Failifmissing=false", DBFile)); the Conn. Open (); -                 }Wuyi                  the             } -             returnConn; Wu}
View Code

Here in order to take into account the previous unencrypted database files, deliberately do the processing, if the database does not exist, directly created, encryption does not exist this problem, mainly for the existing database has a Try...catch exception handling, the individual has been verified, can be used directly.

C # leverages SQLite to create databases for. DB and. LOGDB encryption and decryption and SQLite

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.