# 失效提醒
Chrome Blog
大约在 2024.7 附近,谷歌增强了对 Cookie 的加密,现非 Chrome 的进程无法进行解密,故此文章的做法只能适用于老版本的 Chrome,敬请注意。
# 写在前面
哔哩哔哩的动态接口突然变得需要 Cookie 了,Cookie 这种东西变的很快,如果每次失效都手写一遍岂不是很麻烦,还是自动采集浏览器的 Cookie 吧
代码抄自 Gist,改编为了 C# 版本
# AES 解密
.Net 自从.NetCore3.0 之后,在 System.Security.Cryptography 内内置了相关的算法,对于不支持的版本需要类似于 BouncyCastle 的加密算法库
# >= .NetCore3.0
1 | using System.Security.Cryptography; |
# < .NetCore3.0
1 | using Org.BouncyCastle.Crypto.Parameters; |
# 代码
# 调用 CryptUnprotectData
1 | private const int CRYPTPROTECT_UI_FORBIDDEN = 0x1; |
# SQLite 支持
使用了 SQLSugar
1 | using SqlSugar; |
# 主体部分
进行解密时,Chrome 应当处于关闭状态,否则 Cookie 文件无法读取
- 获取 Cookie 数据库路径,并复制出来
- 读取 Chrome 的 Key,并使用
CryptUnprotectDataAPI 解密 - 读取数据库文件,查询需要的 Cookie 并解密
1 | public static Dictionary<string, string> QueryCookies(string domain) |
# 结果

