How to use the crypto-js/aes.decrypt function in crypto-js

To help you get started, we’ve selected a few crypto-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github softvar / secure-ls / src / index.js View on Github external
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) {
github bitshares / bitsharesjs / lib / ecc / src / aes.js View on Github external
_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
        });
    }
github peerplays-network / peerplays-core-gui / lib / ecc / src / aes.js View on Github external
_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});
    }
github lyrictenor / electron-triage-for-github / lib / utils / cryptData.js View on Github external
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);
}
github olymp / olymp / packages / crypt / index.js View on Github external
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
github maxdeviant / redux-persist-transform-encrypt / src / sync.js View on Github external
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)
github CityOfZion / neon-js / packages / neon-core / src / wallet / nep2.ts View on Github external
(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);
github bipbop / harlan / src / js / internals / modules / iugu.js View on Github external
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;
        };