I've created this, and it's able to get the cookies from Google Chrome when given a specific domain name. However, the values are decrypted. I know there must be a way I can modify my code to decrypt these values.
using Microsoft.Data.Sqlite;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Test
{
public class Test
{
public List<Data> GetCookies(string hostname)
{
List<Data> data = new List<Data>();
if (ChromeCookiesExists())
{
try
{
using (var conn = new SqliteConnection($"Data Source={ChromeCookiePath}"))
using (var cmd = conn.CreateCommand())
{
cmd.CommandText = $"SELECT name,encrypted_value,host_key FROM cookies WHERE host_key = '{hostname}'";
conn.Open();
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
if (!data.Any(a => a.Name == reader.GetString(0)))
{
data.Add(new Data()
{
Name = reader.GetString(0),
Value = reader.GetString(1) //HERE is my problem because this returns encrypted value not decrypted
});
}
}
}
conn.Close();
}
}
catch { }
}
return data;
}
private string ChromeCookiePath = @"C:\Users\" + Environment.UserName + @"\AppData\Local\Google\Chrome\User Data\Default\Cookies";
private bool ChromeCookiesExists()
{
if (File.Exists(ChromeCookiePath))
return true;
return false;
}
public class Data
{
public string Name { get; set; }
public string Value { get; set; }
}
}
}
This code outputs a struct called Data which contains the name and the value of the cookie (just not decrypted atm).