Skip to content

appData keys can contain multiple key value pairs. Find the needed ke… #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/utils/decrypt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ module.exports = decrypt;
function decrypt(object, keys) {
const cryptoKey = object.appData.find(item => item.key === 'crypto-key');
if (!cryptoKey) throw new Error('crypto-key is missing');
let getKeyVal = (keyVals, key) => keyVals.includes(key + '=') ?
keyVals.split(';').filter(keyVal => keyVal.includes(key + '='))[0].split(/=(.+)/)[1] : '';
const salt = object.appData.find(item => item.key === 'encryption');
if (!salt) throw new Error('salt is missing');
const dh = crypto.createECDH('prime256v1');
dh.setPrivateKey(keys.privateKey, 'base64');
const params = {
version : 'aesgcm',
authSecret : keys.authSecret,
dh : cryptoKey.value.slice(3),
dh : getKeyVal(cryptoKey.value, 'dh'),
privateKey : dh,
salt : salt.value.slice(5),
salt : getKeyVal(salt.value, 'salt'),
};
const decrypted = ece.decrypt(object.rawData, params);
return JSON.parse(decrypted);
Expand Down