【问题标题】:SQLite C# returns the wrong bytes from the databaseSQLite C# 从数据库返回错误的字节
【发布时间】:2021-03-15 01:43:19
【问题描述】:

我正在尝试从 Chrome 数据库中检索密码,它在使用 Python 时运行良好,但在使用 C# 时我得到不同的字节。

python代码在从数据库中查询密码时返回以下内容(十六进制值“76 31 30”是v10部分):

0x76 0x31 0x30 0xd2 0x72 0x89 0xc7 0xcf ...

C# 代码...

string passwordColumn = reader.GetString(3); // returns third column
byte[] passBytes= Encoding.UTF8.GetBytes(passwordColumn); // get bytes from string
Console.WriteLine(BitConverter.ToString(passBytes)); // pretty print

...返回以下内容:

76-31-30-EF-BF-BD-72-EF-BF-BD-EF-BF-BD ...

为什么我所做的所有其他查询都返回正确的字符串,但只有当我想要 password_value 列时它才正确返回前三个字节?

有趣的是,当我尝试用这个检查字节时:

foreach (int a in passwordColumn) {
    Console.WriteLine(a);
}

我得到这个作为输出:

118
49
48
65533
114
65533
65533
65533
88
114
106
65533
65533
...

只有不是 65533 的值才是正确的,这是为什么呢?为什么有些字节是正确的,而其他的却不是?最重要的是:如何解决这个问题?

【问题讨论】:

  • 可能和你使用的驱动有关。我不确定。数据库名称是什么,有机会我可以试一试。
  • @NoChance 我尝试使用 .NET 5 和 .NET Framework 4.7.2、System.Data.SQLite 和 Microsoft.Data.Sqlite,在每种情况下我都得到了相同的结果。数据库名称为“Login Data”,位于“AppData\Local\Google\Chrome\User Data\Default\Login Data”

标签: c# .net database sqlite google-chrome


【解决方案1】:

Unicode 字符 65533(在 UTF-8 中编码为 EF BF BD)是 replacement character 用于替换未知、无法识别或无法表示的字符。

好像列的数据类型不是TEXT而是BLOB,你应该用GetBytes()而不是GetString()

【讨论】:

  • 我偶然发现了这个 GetBytes() 方法,但我误解了它,对此我深表歉意。顺便说一句,谢谢你的解释。
猜你喜欢
  • 2022-01-03
  • 2019-10-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-30
  • 1970-01-01
相关资源
最近更新 更多