How to use sjcl - 10 common examples

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 kegesch / passman-ios / src / lib / services / CryptoService.ts View on Github external
export function encrypt(text: string, key: string): string {
	if (!text || !key) {
		throw new Error('Could not encrypt empty text or with empty key.');
	}

	try {
		// @ts-ignore: TS2345: Argument of type 'string' is not assignable to parameter of type 'SjclElGamalPublicKey'.
		const cipherEncrypted = sjcl.encrypt(key, text, cipherConfig);
		return Base64.btoa(cipherEncrypted.toString());
	} catch (err) {
		throw new Error('Could not encrypt: SJCL Error: ' + err);
	}
}
github intervalue / intervalue-lightnode-2.0-testnet / angular-bitcore-wallet-client / bitcore-wallet-client / lib / credentials.js View on Github external
Credentials.prototype.setPrivateKeyEncryption = function(password, opts) {
  if (this.xPrivKeyEncrypted)
    throw new Error('Encrypted Privkey Already exists');

  if (!this.xPrivKey)
    throw new Error('No private key to encrypt');


  this.xPrivKeyEncrypted = sjcl.encrypt(password, this.xPrivKey, opts);
  if (!this.xPrivKeyEncrypted)
    throw new Error('Could not encrypt');

  if (this.mnemonic)
    this.mnemonicEncrypted = sjcl.encrypt(password, this.mnemonic, opts);
};
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 byteball / obyte-gui-wallet / angular-bitcore-wallet-client / bitcore-wallet-client / lib / credentials.js View on Github external
Credentials.prototype.setPrivateKeyEncryption = function(password, opts) {
  if (this.xPrivKeyEncrypted)
    throw new Error('Encrypted Privkey Already exists');

  if (!this.xPrivKey)
    throw new Error('No private key to encrypt');


  this.xPrivKeyEncrypted = sjcl.encrypt(password, this.xPrivKey, opts);
  if (!this.xPrivKeyEncrypted)
    throw new Error('Could not encrypt');

  if (this.mnemonic)
    this.mnemonicEncrypted = sjcl.encrypt(password, this.mnemonic, opts);
};
github ringringringring / trustnote-wallet / angular-bitcore-wallet-client / bitcore-wallet-client / lib / credentials.js View on Github external
Credentials.prototype.setPrivateKeyEncryption = function (password, opts) {
    if (this.xPrivKeyEncrypted)
        throw new Error('Encrypted Privkey Already exists');

    if (!this.xPrivKey)
        throw new Error('No private key to encrypt');

    this.xPrivKeyEncrypted = sjcl.encrypt(password, this.xPrivKey, opts);
    if (!this.xPrivKeyEncrypted)
        throw new Error('Could not encrypt');

    if (this.mnemonic)
        this.mnemonicEncrypted = sjcl.encrypt(password, this.mnemonic, opts);
};

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