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. API接口开发规范

    API接口是不同软件系统之间进行通信的重要方式,良好的API接口设计规范可以提高系统的可维护性.可扩展性和易用性.本文介绍了一套详细的API接口开发规范,包括命名规范.请求和响应规范.安全规范等内容, ...

  2. Java实现动态数组【数据结构与算法】

    1.数组 类型固定.长度固定 连续的内存空间 顺序存储.随机读取 查询快.新增删除慢.最好初始化的时候就指定数组大小.这样就可以避免一定的数组扩容出现的内存消耗. import java.util.A ...

  3. mvn命令将 ueditor百度富文本编辑器 所需jar包上传到本地maven仓库

    1.需要的jar包位置 在解压后的路径中的jsp/lib下:(UEditor\jsp\lib) 2.打开命令行窗口 WIN+R 输入cmd并回车 直接在命令行输入如下命令:(一个一个输入运行,里面的路 ...

  4. ET介绍——浅谈AI框架

    AI框架 1. 几种AI的设计 AI在游戏中很多,但是为什么大家总是感觉ai编写起来十分困难,我后来思考了一番,主要原因是使用的方法不当.之前大家编写ai主要有几种方案: a. 状态机 我是不知道谁想 ...

  5. 3D Object Detection Essay Reading 2024.04.01

    Swin Transformer paper: https://arxiv.org/abs/2103.14030 (ICCV 2021) code:https://github.com/microso ...

  6. #分治#JZOJ 4211 送你一颗圣诞树

    题目 有\(m+1\)棵树分别为\(T_{0\sim m}\),一开始只有\(T_0\)有一个点,编号为0. 对于每棵树\(T_i\)由T_{a_i}\(的第\)c_i\(个点与\)T_{b_i}\( ...

  7. JDK10的新特性:var和匿名类

    目录 简介 匿名类中自定义变量 lambda表达式中的匿名类 总结 简介 匿名类相信大家都用过了,学过JDK8中的lambda表达式之后,可以发现有些匿名类是可以用lambda表达式来替代的,能够被替 ...

  8. Docker学习路线13:部署容器

    部署容器是使用Docker和容器化管理应用程序更高效.易于扩展和确保跨环境一致性性能的关键步骤.本主题将为您概述如何部署Docker容器以创建和运行应用程序. 概述 Docker容器是轻量级.可移植且 ...

  9. Docker 学习之道: 容器注册表及其最佳实践

    容器注册表是Docker容器镜像的集中存储和分发系统.它允许开发人员以这些镜像的形式轻松共享和部署应用程序.容器注册表在容器化应用程序的部署中发挥着关键作用,因为它们提供了一种快速.可靠和安全的方式, ...

  10. HMS Core打造影音娱乐行业解决方案,助推视听新浪潮

    6月28日,HDD·HMS Core. Sparkle影音娱乐线上沙龙在各大直播平台与开发者们见面.本次线上沙龙围绕影音娱乐行业现状观察和趋势.用户数据洞察分析以及HMS Core影音娱乐行业解决方案 ...