Skip to content
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