How to use the libsodium-wrappers.crypto_secretbox_open_easy function in libsodium-wrappers

To help you get started, we’ve selected a few libsodium-wrappers 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 Zefau / ioBroker.roomba / library.js View on Github external
decrypt(key, message)
	{
		try
		{
			message = _sodium.from_hex(message);
			return _sodium.to_string(_sodium.crypto_secretbox_open_easy(message.slice(_sodium.crypto_secretbox_NONCEBYTES), message.slice(0, _sodium.crypto_secretbox_NONCEBYTES), _sodium.from_hex(key)));
		}
		catch(e)
		{
			this._adapter.log.warn(JSON.stringify(e.message));
			return false;
		}
	}
github Zefau / ioBroker.roomba / lib / encryption.js View on Github external
decrypt(key, message)
	{
		try
		{
			let cypherText = new Buffer(payload, 'base64');
			let nonce = cypherText.slice(0, _sodium.crypto_secretbox_NONCEBYTES);
			
			let encryptionKey = new Buffer(32);
			encryptionKey.fill(0);
			encryptionKey.write(key);
			
			return _sodium.crypto_secretbox_open_easy(cypherText.slice(_sodium.crypto_secretbox_NONCEBYTES), nonce, encryptionKey, 'text');
		}
		catch(e)
		{
			this._adapter.log.warn(e.message);
			return false;
		}
	}
}
github samuelmaddock / metastream / packages / metastream-app / src / platform / web / crypto.ts View on Github external
export const decrypt = (cipher: Data, nonce: Data, key: Key) => {
  if (cipher.length < sodium.crypto_secretbox_MACBYTES) return null
  let msg
  try {
    msg = sodium.crypto_secretbox_open_easy(cipher, nonce, key)
  } catch (e) {
    return null
  }
  return msg
}
github maidsafe / safe_examples / dns_example / src / scripts / safe_api / request_manager.js View on Github external
var decrypt = function(data) {
    var ct = new Uint8Array(data.length);
    for (var i=0; i < data.length; i++) {
      ct[i] = data.readUInt8(i);
    }
    var decryptedData = sodium.crypto_secretbox_open_easy(ct, encryptionNonce, encryptionKey);
    return new Buffer(getValuesFromMap(decryptedData)).toString();
  };
github ecadlabs / taquito / packages / taquito-signer / src / taquito-signer.ts View on Github external
decrypt = constructedKey => {
        const salt = toBuffer(constructedKey.slice(0, 8));
        const encryptedSk = constructedKey.slice(8);
        const encryptionKey = pbkdf2.pbkdf2Sync(passphrase, salt, 32768, 32, 'sha512');

        return sodium.crypto_secretbox_open_easy(
          new Uint8Array(encryptedSk),
          new Uint8Array(24),
          new Uint8Array(encryptionKey)
        );
      };
    }