Search code examples
c#nosqllitedb

How to check if LiteDB database file has password or not in C#?


I have a number of LiteDB database files. Some of them have password. when I open these files in the application, for those one which have password I will get the Invalid database password exception.

How I can check the database file before opened it to find if it has password protected or not? So I can show an input box to the user to get the password.

I'm using LiteDB in Windows WPF application (C#).

Thanks and sorry for my English. :)


Solution

  • there is no direct option to test if a datafile are encrypted or nor. But you can test some header bytes to check if datafile contains hash password (this works for v4).

    You can open datafile and tests 20 bytes (start in position 67) - if all bytes are 0 means this datafile has no password.