Skip to content

Instantly share code, notes, and snippets.

@zapalote
Created May 1, 2021 14:39
Show Gist options
  • Save zapalote/0d9a0dbeef867f6df51552ad9e607ca6 to your computer and use it in GitHub Desktop.
Save zapalote/0d9a0dbeef867f6df51552ad9e607ca6 to your computer and use it in GitHub Desktop.
// decode credentials upon receiving them from store
function decodeCredentials(crd){
// decrypt it first
const dec = CryptoJS.AES.decrypt(crd, saltCredentials).toString(CryptoJS.enc.Utf8);
// extract the creds length and pepper step
const len = dec.charCodeAt(0) - 96;
const step = dec.charCodeAt(1) - 96;
let i = 0, j = 2, d = [];
// extract the pepper from the salt
while( i < len ){
d[i++] = dec[j];
j += step;
}
// return the json object
return JSON.parse(d.join(''));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment