Cross-platform encrypted SQLite 3-wxsqlite3

Source: Internet
Author: User

SQLite 3 open-source Edition does not include the encryption function. It is unacceptable for a local database to have no encryption function. You only need to open the database with notepad to view the data saved in the database, security is more or less affected. One way is to encrypt the content and save it to the database. However, if you encounter a similar like or comparing the field content with the field content, this will not work. The cure is to enable native SQLite to support encryption. Fortunately, the author of SQLite has reserved interfaces for encryption and decryption, and many enthusiasts have modified the source version to add encryption functions. If you are also paying attention to it, you may have read a lot of articles on how to add encryption. At the same time, I am not very familiar with related technologies, so I will not explain how to modify the source code. Although there are a large number of articles on the Internet to teach you how to modify the source code, the compiled DLL file is not provided, or the provided dll version is too low. Here is an open-source project wxsqlite3, which is a C ++ warpper of SQLite. It implements the encryption function of SQLite and uses the AES algorithm for encryption. You can download the latest package here. The directory \ sqlite3 \ secure contains these directories, and the sqlite3.dll file under the aes128 directory, it is a compiled SQLite 3 DLL file encrypted with the 128-bit AES algorithm, while the 256-bit AES algorithm is used in the AES 256 directory, in the src directory, the source code of SQLite 3 is encrypted. At the same time, the wxsqlite3 project is updated quickly and you can always download a newer package. The 256-bit AES encryption algorithm will be tested starting from version 1.9.8. It is estimated that the version will be available soon.

It is easy to use. First open the database sqlite3_open, and then execute sqlite3_key before the database operation. Otherwise, an error is returned.

Sqlite3_key is the input key. If the database is encrypted, you must first execute this function and enter the correct key to perform the operation. If the database is not encrypted, if you perform database operations after executing this function, the error "the database is encrypted or not a database file" may occur.

Int sqlite3_key (sqlite3 * dB, const void * pkey, int nkey), DB indicates the database, pkey indicates the key, and nkey indicates the key length. Example: sqlite3_key (dB, "ABC", 3 );

Sqlite3_rekey is used to change the key or add or clear the key to an unencrypted database. Before changing or clearing the key, you must correctly execute sqlite3_key. After sqlite3_rekey is correctly executed, you can operate the database normally before sqlite3_close closes the database. You do not need to execute sqlite3_key.

Int sqlite3_rekey (sqlite3 * dB, const void * pkey, int nkey), same as above.

Clear the key as sqlite3_rekey (dB, null, 0 ).

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.