Skip to content

Instantly share code, notes, and snippets.

@juliocesar
Forked from eyecatchup/calc-sapisidhash.js
Created May 11, 2023 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliocesar/c060224ebdaf1ba2f1c95bd7709f8453 to your computer and use it in GitHub Desktop.
Save juliocesar/c060224ebdaf1ba2f1c95bd7709f8453 to your computer and use it in GitHub Desktop.
Calculate SAPISIDHASH
async function getSApiSidHash(SAPISID, origin) {
function sha1(str) {
return window.crypto.subtle.digest("SHA-1", new TextEncoder("utf-8").encode(str)).then(buf => {
return Array.prototype.map.call(new Uint8Array(buf), x=>(('00'+x.toString(16)).slice(-2))).join('');
});
}
const TIMESTAMP_MS = Date.now();
const digest = await sha1(`${TIMESTAMP_MS} ${SAPISID} ${origin}`);
return `${TIMESTAMP_MS}_${digest}`;
}
const SAPISIDHASH = await getSApiSidHash(document.cookie.split('SAPISID=')[1].split('; ')[0], 'https://photos.google.com');
console.log(SAPISIDHASH);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment