sqlite - Encrypted cookies in Chrome -
i working on c# forms application needs access specific cookie on computer, can fine. here's issue:
google stores cookies in sqlite, , i've downloaded sqlite database browser me @ these values. surprises me half of cookie values shows empty (including 1 need), though not.
the db file located at:
c:\users\%username%\appdata\local\google\chrome\user data\default\cookies
on chrome have addon called "edit cookie" allows me directly modify cookies on website i'm on. addon can read these cookies, , web browser can parse values through http when needed different requests, there - still, sqlite browser, , custom code both come conclusion particular value field empty.
why that? somehow prevents field being read applications?
i've run same problem, , code below provides working example interested. credit scherling, dpapi spot on.
public class chromecookiereader { public ienumerable<tuple<string,string>> readcookies(string hostname) { if (hostname == null) throw new argumentnullexception("hostname"); var dbpath = environment.getfolderpath(environment.specialfolder.localapplicationdata) + @"\google\chrome\user data\default\cookies"; if (!system.io.file.exists(dbpath)) throw new system.io.filenotfoundexception("cant find cookie store",dbpath); // race condition, i'll risk var connectionstring = "data source=" + dbpath + ";pooling=false"; using (var conn = new system.data.sqlite.sqliteconnection(connectionstring)) using (var cmd = conn.createcommand()) { var prm = cmd.createparameter(); prm.parametername = "hostname"; prm.value = hostname; cmd.parameters.add(prm); cmd.commandtext = "select name,encrypted_value cookies host_key = @hostname"; conn.open(); using (var reader = cmd.executereader()) { while (reader.read()) { var encrypteddata = (byte[]) reader[1]; var decodeddata = system.security.cryptography.protecteddata.unprotect(encrypteddata, null, system.security.cryptography.dataprotectionscope.currentuser); var plaintext = encoding.ascii.getstring(decodeddata); // looks ascii yield return tuple.create(reader.getstring(0), plaintext); } } conn.close(); } } }
Comments
Post a Comment