首页 > 解决方案 > 从 mac os 上的 sqlite db 解密 chrome cookie

问题描述

我使用配置文件文件夹中的 sqlite db Cookies。它有encrypted_value字段。有很多例子和描述它是如何在每个平台上加密的。所以在Linux上我使用以下内容:

linuxPwd = 'peanuts';
var derivedKey = crypto.pbkdf2Sync(linuxPwd, 'saltysalt', 1, 16, 'sha1');
var decrypted = decrypt(derivedKey, encryptedValue);

decrypt功能:

function decrypt(key, encryptedData) {

var decipher, decoded, final, padding, iv = new Buffer.from(new Array(16 + 1).join(' '), 'binary');

decipher = crypto.createDecipheriv('aes-128-cbc', key, iv);

// Remove 'v10' from start
encryptedData = encryptedData.slice(3);
decoded = decipher.update(encryptedData);

final = decipher.final();
final.copy(decoded, decoded.length - 1);
padding = decoded[decoded.length - 1];
if (padding) decoded = decoded.slice(0, decoded.length - padding);

return decoded.toString('utf8');

}

所以在 linux 密码是peanuts(如果没有使用钥匙串)和迭代次数是1. MacOS 的一切都应该相同,除了迭代次数1003和密码来自钥匙串。

我从钥匙串中手动获取了Chrome Safe Storage项目的密码并增加了迭代次数:

macPwd = 'ELrTZt24OdPhg93BjAIJhA==';
var derivedKey = crypto.pbkdf2Sync(macPwd, 'saltysalt', 1003, 16, 'sha1');

它在 linux 上工作正常,解码数据是正确的,但在 mac 上我收到损坏的字节。有什么问题?如果我知道编码字符串,也许我可以找到哪个参数是错误的?

标签: macossqlitegoogle-chromeencryptionpbkdf2

解决方案


对于那些也将陷入此错误的人。我手动下载并构建了铬并调试了加密过程。在某些情况下,当 keychain 不可用时,加密和解密的密码是mock_password.


推荐阅读