Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!data) {
return jsonData;
}
deCompressedData = data; // saves else
if (this._isCompression || isAllKeysData) { // meta data always compressed
deCompressedData = LZString.decompressFromUTF16(data);
}
decodedData = deCompressedData; // saves else
if (this._isBase64 || isAllKeysData) { // meta data always Base64
decodedData = Base64.decode(deCompressedData);
} else {
this.getEncryptionSecret(key);
if (this._isAES) {
bytes = AES.decrypt(deCompressedData.toString(), this.utils.encryptionSecret);
} else if (this._isDES) {
bytes = DES.decrypt(deCompressedData.toString(), this.utils.encryptionSecret);
} else if (this._isRabbit) {
bytes = RABBIT.decrypt(deCompressedData.toString(), this.utils.encryptionSecret);
} else if (this._isRC4) {
bytes = RC4.decrypt(deCompressedData.toString(), this.utils.encryptionSecret);
}
if (bytes) {
decodedData = bytes.toString(enc._Utf8);
}
}
try {
jsonData = JSON.parse(decodedData);
} catch (e) {
_decrypt_word_array(cipher) {
// https://code.google.com/p/crypto-js/#Custom_Key_and_IV
// see wallet_records.cpp master_key::decrypt_key
return AES.decrypt({ciphertext: cipher, salt: null}, this.key, {
iv: this.iv
});
}
_decrypt_word_array(cipher) {
// https://code.google.com/p/crypto-js/#Custom_Key_and_IV
// see wallet_records.cpp master_key::decrypt_key
return AES.decrypt({ ciphertext: cipher, salt: null}, this.key, {iv: this.iv});
}
export function decryptData(saltAndCrypted) {
if (!saltAndCrypted) {
return saltAndCrypted;
}
const salt = saltAndCrypted.slice(prefix.length, prefix.length + saltDigit);
const crypted = saltAndCrypted.slice(prefix.length + saltDigit);
return AES.decrypt(crypted, salt).toString(cryptoJsEncUtf8);
}
export var decrypt = function (data, key) {
if (!data) {
return null;
}
var result = data;
if (data && key) {
var AES = require('crypto-js/aes');
var Utf8 = require('crypto-js/enc-utf8');
result = AES.decrypt(data, key).toString(Utf8);
}
else {
var Base64 = require('crypto-js/enc-base64');
var Utf8 = require('crypto-js/enc-utf8');
result = Base64.parse(data).toString(Utf8);
}
result = result ? JSON.parse(result) : undefined;
return result || {};
};
//# sourceMappingURL=index.js.map
makeDecryptor(state => {
try {
const bytes = AES.decrypt(state, secretKey)
const decryptedString = bytes.toString(CryptoJSCore.enc.Utf8)
return JSON.parse(decryptedString)
} catch (err) {
throw new Error(
'Could not decrypt state. Please verify that you are using the correct secret key.'
)
}
}, onError)
(error: Error, _: number, key: string) => {
if (error != null) {
reject(error);
} else if (key) {
const derived = Buffer.from(key).toString("hex");
const derived1 = derived.slice(0, 64);
const derived2 = derived.slice(64);
const ciphertext = {
ciphertext: enc.Hex.parse(encrypted),
salt: "",
iv: ""
};
const decrypted = AES.decrypt(
ciphertext,
enc.Hex.parse(derived2),
AES_OPTIONS
);
const privateKey = hexXor(decrypted.toString(), derived1);
const account = new Account(privateKey);
const newAddressHash = SHA256(SHA256(
enc.Latin1.parse(account.address)
) as any)
.toString()
.slice(0, 8);
if (addressHash !== newAddressHash) {
reject(new Error("Wrong password or scrypt parameters!"));
}
log.info(`Successfully decrypted ${encryptedKey}`);
resolve(account.WIF);
const getToken = password => {
if (!TwinBcrypt.compareSync(password, data.password)) {
return false;
}
Iugu.createPaymentToken(JSON.parse(
AES.decrypt(data.token, password)
.toString(CryptoJS.enc.Utf8)
.replace(/^[^{]+/, '')), paymentToken => {
callback(paymentToken);
});
return true;
};