sqlite 添加用户密码的方法
1、首先添加引用

2、然后替换Bin下的x86/x64文件夹下的文件

3、添加修改密码的代码
public bool SetSqlitePsd(string passWord) { bool result = false; try { using (SQLiteConnection cnn = new SQLiteConnection(CONNSTR)) { cnn.Open(); cnn.ChangePassword(passWord); result = true; } } catch (Exception ex) { Debug.WriteLine(ex.Message + "数据库或已加密"); } return result; } public bool ClearSqlitePsd(string passWord) { bool result = false; try { using (SQLiteConnection cnn = new SQLiteConnection(CONNSTR)) { cnn.SetPassword(passWord); cnn.Open(); cnn.ChangePassword(""); result = true; } } catch (Exception ex) { Debug.WriteLine(ex.Message + "数据库或已解密"); } return result; }
参考文档:
https://blog.csdn.net/xaiqpl/article/details/125271496
以上方法只能在Windows平台运行,跨平台的方法:
https://learn.microsoft.com/zh-cn/dotnet/standard/data/sqlite/encryption?tabs=net-cli
posted on 2025-12-10 08:06 wangzhiliang 阅读(3) 评论(0) 收藏 举报
浙公网安备 33010602011771号