I am currently working on a Node.js script, which logs me into a website and automatically opens the browser with me being logged in. I have been trying to add a cookie (gathered from the login POST-request) to the "cookie" database of chrome, but I am failing at getting the encryption right. The Stackoverflow thread, I came along regarding the encryption of Cookies was this one: Chrome 80 how to decode cookies But that thread was about decrypting a cookie and not encrypting it.
function encryptCookie(cookie, key){
const iv = crypto.randomBytes(16);
let cipher = crypto.createCipheriv('aes-256-gcm', key, iv);
let encrypted = cipher.update(cookie);
encrypted = Buffer.concat([Buffer.from('v10'), encrypted, cipher.final()]);
console.log(`Encrypted: ${encrypted}`);
return encrypted;
}
As for the "key" I am using the decrypted Key from Local State. (I decrypted the key using a DPAPI module.) I know that the encrypted cookie always starts with v10 so i added it as a prefix, but the encrypted Cookie is still too short.
I know I could work with a webscraper or just safe my password on the page, but I wanted to interact with the cookie Database and HTTP-requests.