简体   繁体   English

如何在 C# 中检查 LiteDB 数据库文件是否有密码?

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

I have a number of LiteDB database files.我有许多 LiteDB 数据库文件。 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#).我在 Windows WPF 应用程序 (C#) 中使用 LiteDB。

Thanks and sorry for my English.感谢和抱歉我的英语。 :) :)

对于 LiteDB v5.0.x 数据文件(更具体地说,v8 数据文件格式),第一个字节用于指示文件是否加密:0 表示未加密,1 表示加密。

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).但是您可以测试一些标头字节以检查数据文件是否包含哈希密码(这适用于 v4)。

You can open datafile and tests 20 bytes (start in position 67) - if all bytes are 0 means this datafile has no password.您可以打开数据文件并测试 20 个字节(从位置 67 开始)-如果所有字节均为 0,则表示此数据文件没有密码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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