用Cryptography解密谷歌浏览器的登录密码(login data)失败
自己电脑因为重装系统,但是谷歌浏览器记录的密码已经不能导出了,所以就尝试从备份文件里面导出已经记录的密码。使用C#对login data文件进行解密时,报错提示“该项不适于在指定状态下使用。”。
电脑系统是win7,谷歌浏览器版本是104.0.5112.102 (正式版本) (64 位)
电脑重装后的系统版本、用户名、密码与原系统一致。
代码如下
public static void QueryDB()
{
connection.Open();
// query the rows
SQLiteCommand command = connection.CreateCommand();
command.CommandText = "select * from logins";
SQLiteDataAdapter adapter = new SQLiteDataAdapter(command);
DataTable table = new DataTable();
adapter.Fill(table);
foreach (DataRow row in table.Rows)
{
byte[] password = (byte[])row["password_value"];
String password_d = Decrypt(password);
Console.WriteLine(password_d);
Console.WriteLine($"url: {row["origin_url"]} username: {row["username_value"]}");
}
connection.Close();
}
public static string Decrypt(byte[] EncryptedData)
{
if (EncryptedData == null || EncryptedData.Length == 0)
{
return null;
}
byte[] decryptedData = ProtectedData.Unprotect(EncryptedData, null, DataProtectionScope.CurrentUser);
return Encoding.UTF8.GetString(decryptedData);
}
报错如下
未处理System.Security.Cryptography.CryptographicException
HResult=-2146893813
Message=该项不适于在指定状态下使用。
Source=System.Security
StackTrace:
在 System.Security.Cryptography.ProtectedData.Unprotect(Byte[] encryptedData, Byte[] optionalEntropy, DataProtectionScope scope)
在 ChromePasswords.Chrome2.Decrypt(Byte[] EncryptedData) 位置 G:\chrome-password-decrypt-main\ChromePasswords\Chrome2.cs:行号 48
在 ChromePasswords.Chrome2.QueryDB() 位置 G:\chrome-password-decrypt-main\ChromePasswords\Chrome2.cs:行号 36
在 ChromePasswords.Program.Main(String[] args) 位置 G:\chrome-password-decrypt-main\ChromePasswords\Program.cs:行号 14
在 System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException:
我的解答思路和尝试过的方法
根据网上查到的都是让删除“C:\Documents and Settings\skymid\Application Data\Microsoft\Crypto”、“C:\Users\skymid\Application Data\Microsoft\Crypto”、“C:\Users\skymid\AppData\Roaming\Microsoft\Crypto”或者“C:\ProgramData\Microsoft\Crypto”目录下的所有文件,也试过了不行。