您好我正在尝试从 sqlite数据库表中获取数据,但数据受 CryptProtectData 保护。
有人能告诉我如何解密数据?
Public Sub Name()
Dim ConnectionString As String = "Data Source=Employee.sqlite"
Dim SQLString As String = "SELECT dateofbirth From info"
Dim dt As DataTable = Nothing
Dim ds As New DataSet
Dim con As New SQLiteConnection(ConnectionString)
Dim cmd As New SQLiteCommand(SQLString, con)
con.Open()
Dim Reader As SQLite.SQLiteDataReader = cmd.ExecuteReader
While Reader.Read
Console.WriteLine(Reader("dateofbirth"))
End While
End Sub
在上面的代码中,字段dateofbirth是加密的。
答案 0 :(得分:0)
在不知道您的数据如何编码和存储在数据库中的情况下,我只能给出一个通用示例,但希望这会让您开始和/或指向不同的问题。此示例假定存储在数据库中的数据是UTF8编码的字符串。
Imports System.Security.Cryptography
'...
Dim Reader As SQLite.SQLiteDataReader = cmd.ExecuteReader
While Reader.Read
' Get data from BLOB column
Dim encData As Byte() = DirectCast(rdr("dateofbirth"), Byte())
' Decrypt the data using DPAPI for the current user
Dim outputData As Byte() = ProtectedData.Unprotect(encData, Nothing, DataProtectionScope.CurrentUser)
' Convert the decrypted data back to a string using UTF8 encoding
Dim output As String = Encoding.UTF8.GetString(outputData)
Console.WriteLine(output)
End While
您需要引用System.Security.dll
并显示导入以查找ProtectedData
类。