简体   繁体   中英

C# Determine if a SQLite database file is password encrypted

Yes, I know that it's possible to attempt connecting to a SQLite database, and then using a try-catch if a password is required. This is not clean code. I am looking for a smarter way to determine if a .sqlite file is encrypted before attempting to connect to it. I am using the System.Data.sqlite dll for this project.

You would have to inspect the SQLite main database file itself.

Excerpt from The SQLite Database File Format :

1.2.4 Reserved bytes per page

SQLite has the ability to set aside a small number of extra bytes at the end of every page for use by extensions. These extra bytes are used, for example, by the SQLite Encryption Extension to store a nonce and/or cryptographic checksum associated with each page.

You're only option is try-catch. Since the entire database file is encrypted , including metadata, there's no specific bit that you can test on. But I believe that try-catch is appropriate when handling an incorrect or missing password.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM