I am trying to write a simple C# console application that will save my chrome passwords. I know that my login data is stored in C:\Users\USER\Appdata\Local\Google\Chrome\User Data\Default\Login Data and the passwords are encrypted but can be decrypted as long as the current user is running the program.
When I try to decrypt the passwords using the Unprotect() method, I get the following error:
System.Security.Cryptography.CryptographicException: The parameter is incorrect
Here is my code:
public void decrypt()
{
//Create a temp file to read from so database isn't locked
string source = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Google\Chrome\User Data\Default\Login Data";
string target = @"tmp\backup";
File.Copy(source, target);
SQLiteConnection sqlite = new SQLiteConnection(@"Data Source="+ target);
try
{
sqlite.Open();
SQLiteCommand cmd = sqlite.CreateCommand();
cmd.CommandText = "SELECT action_url, username_value, password_value FROM logins";
SQLiteDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
//Decrypt password. Problem arises here
var plainText = Encoding.UTF8.GetString(ProtectedData.Unprotect((byte[])reader["password_value"], null, DataProtectionScope.CurrentUser));
}
reader.Close();
sqlite.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
The database seems to be valid because I can grab the username, host names..etc, but I simply cannot decrypt my passwords to plain text. I am logged in as the current user.