How to use the sjcl.decrypt function in sjcl

To help you get started, we’ve selected a few sjcl 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 bitpay / copay-recovery / src / app / services / recovery.service.ts View on Github external
private fromBackup(data: any, m: number, n: number, coin: string, network: string): any {
    try {
      JSON.parse(data.backup);
    } catch (ex) {
      console.log(ex);
      throw new Error('JSON invalid. Please copy only the text within (and including) the { } brackets around it.');
    }

    let payload;
    try {
      payload = sjcl.decrypt(data.password, data.backup);
    } catch (ex) {
      console.log(ex);
      throw new Error('Incorrect backup password');
    }

    payload = JSON.parse(payload);

    // Support for old file formats
    const credentials = payload.credentials ? payload.credentials : payload;
    const key = payload.key ? payload.key : payload;

    if (!credentials.n) {
      // tslint:disable-next-line:max-line-length
      throw new Error('Backup format not recognized. If you are using a Copay Beta backup and version is older than 0.10, please see: https://github.com/bitpay/copay/issues/4730#issuecomment-244522614');
    }
    if ((credentials.m !== m) || (credentials.n !== n)) {
github intervalue / intervalue-lightnode-2.0-testnet / angular-bitcore-wallet-client / bitcore-wallet-client / lib / credentials.js View on Github external
Credentials.prototype.unlock = function(password) {
  $.checkArgument(password);

  if (this.xPrivKeyEncrypted) {
    this.xPrivKey = sjcl.decrypt(password, this.xPrivKeyEncrypted);
    if (this.mnemonicEncrypted) {
      this.mnemonic = sjcl.decrypt(password, this.mnemonicEncrypted);
    }
  }
};
github bitpay / bitcore / lib / walletutils.js View on Github external
WalletUtils.decryptWallet = function(data, password) {
  $.checkArgument(data.enc);
  var extraFields = JSON.parse(sjcl.decrypt(password, data.enc));
  delete data.enc;
  return _.extend(data, extraFields);
};
github bitpay / bitcore-wallet-client / lib / api.js View on Github external
API.prototype._oldCopayDecrypt = function(username, password, blob) {
  var SEP1 = '@#$';
  var SEP2 = '%^#@';

  var decrypted;
  try {
    var passphrase = username + SEP1 + password;
    decrypted = sjcl.decrypt(passphrase, blob);
  } catch (e) {
    passphrase = username + SEP2 + password;
    try {
      decrypted = sjcl.decrypt(passphrase, blob);
    } catch (e) {
      log.debug(e);
    };
  }

  if (!decrypted)
    return null;

  var ret;
  try {
    ret = JSON.parse(decrypted);
  } catch (e) {};
github bitpay / bitcore-mnemonic / packages / bitcore-wallet-client / lib / api.js View on Github external
API.prototype._oldCopayDecrypt = function(username, password, blob) {
  var SEP1 = '@#$';
  var SEP2 = '%^#@';

  var decrypted;
  try {
    var passphrase = username + SEP1 + password;
    decrypted = sjcl.decrypt(passphrase, blob);
  } catch (e) {
    passphrase = username + SEP2 + password;
    try {
      decrypted = sjcl.decrypt(passphrase, blob);
    } catch (e) {
      log.debug(e);
    };
  }

  if (!decrypted)
    return null;

  var ret;
  try {
    ret = JSON.parse(decrypted);
  } catch (e) {};
github bitpay / bitcore-wallet-client / lib / api.js View on Github external
API.prototype._oldCopayDecrypt = function(username, password, blob) {
  var SEP1 = '@#$';
  var SEP2 = '%^#@';

  var decrypted;
  try {
    var passphrase = username + SEP1 + password;
    decrypted = sjcl.decrypt(passphrase, blob);
  } catch (e) {
    passphrase = username + SEP2 + password;
    try {
      decrypted = sjcl.decrypt(passphrase, blob);
    } catch (e) {
      log.debug(e);
    };
  }

  if (!decrypted)
    return null;

  var ret;
  try {
    ret = JSON.parse(decrypted);
  } catch (e) {};
github bitpay / bitcore / packages / bitcore-wallet-client / src / lib / common / utils.ts View on Github external
static decryptMessage(cyphertextJson, encryptingKey) {
    if (!cyphertextJson) return;

    if (!encryptingKey) throw new Error('No key');

    var key = sjcl.codec.base64.toBits(encryptingKey);
    return sjcl.decrypt(key, cyphertextJson);
  }
github kegesch / passman-ios / src / lib / services / CryptoService.ts View on Github external
export function decrypt(cipher: string, key: string): string {
	if (!cipher || !key) {
		throw new Error('Could not decrypt empty ciphertext or with empty key.');
	}

	const cipherObject = Base64.atob(cipher);

	try {
		return sjcl.decrypt(key, cipherObject);
	} catch (err) {
		throw new Error('Could not decrypt: SJCL Error: ' + err);
	}
}
github bitpay / bitcore / lib / walletutils.js View on Github external
WalletUtils.decryptMessage = function(cyphertextJson, encryptingKey) {
  var key = sjcl.codec.base64.toBits(encryptingKey);
  return sjcl.decrypt(key, cyphertextJson);
};

sjcl

Stanford Javascript Crypto Library

(BSD-2-Clause OR GPL-2.0-only)
Latest version published 6 years ago

Package Health Score

62 / 100
Full package analysis

Popular sjcl functions