通过Google浏览器Cookie文件获取cookie信息,80以上版本有效
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以上版本有效的更多相关文章
- Springboot使用Cookie,生成cookie,获取cookie信息(注解与非注解方式)
先 创建一个控制类吧, 其实我没有分层啊,随便做个例子: MyGetCookieController: @RestControllerpublic class MyGetCookieControlle ...
- Python Cookie HTTP获取cookie并处理
Cookie模块同样是Python标准库中的一员,它定义了一些类来解析和创建HTTP 的 cookie头部信息. 一.创建和设置Cookie >>> import Cookie #导 ...
- 设置cookie,获取cookie,删除cookie,修改cookie
怎么设置cookie,怎么设置cookie以及删除cookie和cookie详解 在操作cookie之前,先来看一下cookie长什么样. 可以看到,cookie是一个个键值对(“键=值”的形式)加上 ...
- jquery 设置cookie、删除cookie、获取cookie
1.引入jquery.js <script src="//cdn.bootcss.com/jquery/1.12.4/jquery.js"></script> ...
- php curl 生成的cookie 文件含义 cookie 属性含义
最近用了curl 感觉还是很方便的,看了下curl生成的 cookie 文件 格式 , 对其中一些值的含义不是很明白,去找了些cookie的资料看了下,做下备忘 PHP curl 生成 的 cooki ...
- jquery cookie用法(获取cookie值,删除cookie)
1.引入文件 2.具体操作 $.cookie('the_cookie'); // 读取 cookie $.cookie('the_cookie', 'the_value'); // 存储 cookie ...
- JS 判断浏览器类型,获取位置信息,让手机震动
判断是否是安卓 var isAndroid = /Android/i.test(navigator.userAgent); 判断是否是IOS系统 var isIOS = /iPhone|iPad|iP ...
- Python通过解压ofd文件获取发票信息
实际上ofd.docx.xlsx等文件就是一个压缩文件,是可以被解压处理的.所以我们把一个ofd格式的发票文件解压后就可以看到它的目录,如下: 再用谷歌或者IE打开里面的xml属性的文件,就可以看到发 ...
- JAVAWEB使用保存cookie、删除cookie、获取cookie工具类
package com.test; import org.apache.commons.lang.StringUtils; import org.springframework.util.Assert ...
- js 放置 cookie、获取 cookie、删除 cookie
这块TM的删不掉 代码如下: // 自定义 js cookies var mycookie = { // 放置 set : function(name,value){ var Days = 1; // ...
随机推荐
- verilog之时钟信号的编写2
verilog之时钟信号的编写2 1.时钟信号的特点 时钟信号除了可以根据时序一个个变化列举出来,还可以利用其循环的变化的特点,使用循环执行语句always来实现.这种方法实现的时钟信号可以一直执行且 ...
- KingbaseES例程_普通表在线转分区表(基于规则)
KingbaseES例程_普通表在线转分区表 概述 普通表转分区表,使用视图的替换式规则,以路由方式,实现在线转移数据. 数据准备 /*普通大表*/ create table tab_single a ...
- rv1126 mpp部署加解决问题
rv1126 mpp部署 + test 执行失败问题 1.1 mpp 环境部署 首先在我们自己的sdk中 ~/rv1126_linux_240110/external/mpp 将改目录拷贝到需要的 ...
- IntelliJ IDEA 设置类和方法注释
一.在创建类和文件的时候加注释 1.创建类 在右侧输入: 1 /** 2 * 3 * @author ${USER} 4 * @date ${YEAR}-${MONTH}-${DAY} ${TIME} ...
- Minlexes题解
\(\texttt{Problem Link}\) 简要题意 在一个字符串 \(s\) 中,对于每个后缀,任意删掉一些相邻的相同的字符,使得字符串字典序最小. 注意:删掉之后拼起来再出现的相邻相同字符 ...
- 浅谈JVM整体架构与调优参数
本文分享自华为云社区<[性能优化]JVM整体架构与调优参数说明>,作者: 冰 河. JVM的分类 这里,我们先来说说什么是VM吧,VM的中文含义为:虚拟机,指的是使用软件的方式模拟具有完整 ...
- SQL 日期处理和视图创建:常见数据类型、示例查询和防范 SQL 注入方法
SQL处理日期 在数据库操作中,处理日期是一个关键的方面.确保插入的日期格式与数据库中日期列的格式匹配至关重要.以下是一些常见的SQL日期数据类型和处理方法. SQL日期数据类型 MySQL日期数据类 ...
- NVIDIA实习
额,大意了,之前只是有想准备nvidia的实习,但是具体时间没有关注,结果这下正正好错过 这下提前细细准备一下nvidia的实习了 公众号 Cascatrix 其他经验
- Leetcode-栈的压入弹出序列
/* 输入:pushed = [1,2,3,4,5], popped = [4,5,3,2,1] 输出:true 解释:我们可以按以下顺序执行: push(1), push(2), push(3), ...
- 高并发场景QPS等专业指标揭秘大全与调优实战
高并发场景QPS等专业指标揭秘大全与调优实战 最近经常有小伙伴问及高并发场景下QPS的一些问题,特意结合项目经验和网上技术贴做了一些整理和归纳,供大家参考交流. 一.一直再说高并发,多少QPS才算高并 ...