public class ReadCookie
{
/// <summary>
/// </summary>
/// <param name="hostName"></param>
/// <returns></returns>
public static SeleCookie ReadCookies(string hostName,string cookiePath,string domain)
{
//测试用
cookiePath = @"C: \Users\xxx\AppData\Local\Google\Chrome\User Data\Local State";
domain = "%xxx.com";
SeleCookie cc = new SeleCookie();
if (hostName == null) throw new System.ArgumentNullException("hostName"); var dbPath = System.Environment.GetFolderPath(System.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, but i'll risk it var connectionString = "Data Source=" + dbPath + ";pooling=false"; using (var conn = new System.Data.SQLite.SQLiteConnection(connectionString))
using (var cmd = conn.CreateCommand())
{
conn.Close();
cmd.CommandText = $"select * from cookies where host_key like '{domain}'";
#region 查看cookie表
SQLiteDataAdapter da = new SQLiteDataAdapter(cmd.CommandText, conn);
DataSet ds = new DataSet();
da.Fill(ds, "cookiestable");
#endregion var prm = cmd.CreateParameter();
prm.ParameterName = "hostName";
prm.Value = hostName;
cmd.Parameters.Add(prm); conn.Open();
using (var reader = cmd.ExecuteReader())
{
string encKey = File.ReadAllText(cookiePath);
encKey = JObject.Parse(encKey)["os_crypt"]["encrypted_key"].ToString();
var decodedKey = System.Security.Cryptography.ProtectedData.Unprotect(Convert.FromBase64String(encKey).Skip(5).ToArray(), null, System.Security.Cryptography.DataProtectionScope.LocalMachine);
try
{
var propInfo = typeof(SeleCookie).GetProperties().Where(x => x.IsDefined(typeof(CustomAttribute), false) && x.Name == reader[2].ToString() && !x.Name.Equals("Item"));
while (reader.Read())
{
byte[] encryptedData = (byte[])reader[12];
var _cookie = _decryptWithKey(encryptedData, decodedKey, 3);
foreach (var prop in propInfo)
{
prop.SetValue(cc, _cookie ?? string.Empty);
}
} }
finally
{
conn.Close();
} }
if (conn.State != ConnectionState.Closed)
{
conn.Close();
}
return cc;
} }
private static string _decryptWithKey(byte[] message, byte[] key, int nonSecretPayloadLength)
{
const int KEY_BIT_SIZE = 256;
const int MAC_BIT_SIZE = 128;
const int NONCE_BIT_SIZE = 96; if (key == null || key.Length != KEY_BIT_SIZE / 8)
throw new ArgumentException(String.Format("Key needs to be {0} bit!", KEY_BIT_SIZE), "key");
if (message == null || message.Length == 0)
throw new ArgumentException("Message required!", "message"); using (var cipherStream = new MemoryStream(message))
using (var cipherReader = new BinaryReader(cipherStream))
{
var nonSecretPayload = cipherReader.ReadBytes(nonSecretPayloadLength);
var nonce = cipherReader.ReadBytes(NONCE_BIT_SIZE / 8);
var cipher = new GcmBlockCipher(new AesEngine());
var parameters = new AeadParameters(new KeyParameter(key), MAC_BIT_SIZE, nonce);
cipher.Init(false, parameters);
var cipherText = cipherReader.ReadBytes(message.Length);
var plainText = new byte[cipher.GetOutputSize(cipherText.Length)];
try
{
var len = cipher.ProcessBytes(cipherText, 0, cipherText.Length, plainText, 0);
cipher.DoFinal(plainText, len);
}
catch (InvalidCipherTextException)
{
return null;
}
return Encoding.Default.GetString(plainText);
}
} }

需要引用类库:

System.Security.Cryptography.ProtectedData

BouncyCastle

System.Data.SQLite.Core

Newtonsoft.Json

通过Google浏览器Cookie文件获取cookie信息,80以上版本有效的更多相关文章

  1. Springboot使用Cookie,生成cookie,获取cookie信息(注解与非注解方式)

    先 创建一个控制类吧, 其实我没有分层啊,随便做个例子: MyGetCookieController: @RestControllerpublic class MyGetCookieControlle ...

  2. Python Cookie HTTP获取cookie并处理

    Cookie模块同样是Python标准库中的一员,它定义了一些类来解析和创建HTTP 的 cookie头部信息. 一.创建和设置Cookie >>> import Cookie #导 ...

  3. 设置cookie,获取cookie,删除cookie,修改cookie

    怎么设置cookie,怎么设置cookie以及删除cookie和cookie详解 在操作cookie之前,先来看一下cookie长什么样. 可以看到,cookie是一个个键值对(“键=值”的形式)加上 ...

  4. jquery 设置cookie、删除cookie、获取cookie

    1.引入jquery.js <script src="//cdn.bootcss.com/jquery/1.12.4/jquery.js"></script> ...

  5. php curl 生成的cookie 文件含义 cookie 属性含义

    最近用了curl 感觉还是很方便的,看了下curl生成的 cookie 文件 格式 , 对其中一些值的含义不是很明白,去找了些cookie的资料看了下,做下备忘 PHP curl 生成 的 cooki ...

  6. jquery cookie用法(获取cookie值,删除cookie)

    1.引入文件 2.具体操作 $.cookie('the_cookie'); // 读取 cookie $.cookie('the_cookie', 'the_value'); // 存储 cookie ...

  7. JS 判断浏览器类型,获取位置信息,让手机震动

    判断是否是安卓 var isAndroid = /Android/i.test(navigator.userAgent); 判断是否是IOS系统 var isIOS = /iPhone|iPad|iP ...

  8. Python通过解压ofd文件获取发票信息

    实际上ofd.docx.xlsx等文件就是一个压缩文件,是可以被解压处理的.所以我们把一个ofd格式的发票文件解压后就可以看到它的目录,如下: 再用谷歌或者IE打开里面的xml属性的文件,就可以看到发 ...

  9. JAVAWEB使用保存cookie、删除cookie、获取cookie工具类

    package com.test; import org.apache.commons.lang.StringUtils; import org.springframework.util.Assert ...

  10. js 放置 cookie、获取 cookie、删除 cookie

    这块TM的删不掉 代码如下: // 自定义 js cookies var mycookie = { // 放置 set : function(name,value){ var Days = 1; // ...

随机推荐

  1. Shiro反序列化分析

    前言 Shiro,一个流行的web框架,养活了一大批web狗,现在来对它分析分析.Shiro的gadget是CB链,其实是CC4改过来的,因为Shiro框架是自带Commoncollections的, ...

  2. C#调用C++ (使用C++/CLI)

    简介 C++/CLI(C++ Common Language Infrastructure)是一种允许在 .NET 平台上创建托管代码(managed code)和非托管代码(unmanaged co ...

  3. linux xfce 设置限制亮度滑块的最小亮度,在屏幕里的xfce设置亮度的最小亮度。

    参照 https://docs.xfce.org/xfce/xfce4-power-manager/preferences 使用代码 xfconf-query -c xfce4-power-manag ...

  4. C++ 自动计时

    #include<iostream> #include<chrono> struct Timer { std::chrono::time_point<std::chron ...

  5. redis,mongo,mysql,es区别

    Redis.MongoDB.MySQL和Elasticsearch(ES)都是常用的数据库系统,各有不同的特点和适用场景,具体区别如下: Redis:Redis是一种高性能键值存储数据库,基于内存操作 ...

  6. redis的两种持久化方式

    1.为什么redis需要持久化 答:edis是基于内存的,如果Redis服务器挂了,数据就会丢失 2.有几种方式实现redis的持久化 答:有两种,一种是AOF 持久化,另一种是RDB持久化 一. A ...

  7. 【WCH以太网接口系列芯片】STM32+CH390+Lwip协议栈简单应用测试

    本篇文章基于STM32F103和CH390H芯片进行例程移植及相关注意事项,简单验证TCP\UDP\Ping基础功能. 硬件:STM32F103开发板+沁恒CH390H的评估版图一示,SPI使用接口为 ...

  8. java中的内部类内部接口详解

    目录 简介 内部类 静态内部类 非静态内部类 静态方法内部类 非静态方法的内部类 匿名类 内部接口 总结 简介 一般来说,我们创建类和接口的时候都是一个类一个文件,一个接口一个文件,但有时候为了方便或 ...

  9. winrt新dx截图最小实现

    转自:https://stackoverflow.co/questions/11283015 效果还是很不错的 #include <iostream> #include <Windo ...

  10. 兼容模式下导致数值类型发生隐式转换,SQL在生产上无法正常使用案例

    兼容模式下导致数值类型发生隐式转换,SQL 在生产上无法正常使用案例 本文出处:https://www.modb.pro/db/403148 基于 MogDB 版本 V2.0.1 问题现象 厂商研发描 ...