How to use the libsodium-wrappers.crypto_secretbox_NONCEBYTES 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 samuelmaddock / metastream / packages / metastream-app / src / platform / web / crypto.ts View on Github external
export const nonce = () => sodium.randombytes_buf(sodium.crypto_secretbox_NONCEBYTES)
github Zefau / ioBroker.roomba / library.js View on Github external
encrypt(key, message)
	{
		var nonce = _sodium.randombytes_buf(_sodium.crypto_secretbox_NONCEBYTES);
		try
		{
			return _sodium.to_hex(_concat(Uint8Array, nonce, _sodium.crypto_secretbox_easy(message, nonce, _sodium.from_hex(key))));
		}
		catch(e)
		{
			this._adapter.log.warn(e.message);
			return false;
		}
	}
github maidsafe / safe_examples / dns_example / src / scripts / safe_api / request_manager.js View on Github external
notifierCallback('Handshake failed - ' + handshakeResponse.error.description +
                      '(' + handshakeResponse.error.code + ')');
      return;
    }
    var launcherPublicKey = convertStringAsUnit8Array(handshakeResponse.data.launcher_public_key);
    var decryptedSymmKey;
    try {
      decryptedSymmKey = sodium.crypto_box_open_easy(convertStringAsUnit8Array(handshakeResponse.data.encrypted_symm_key), HandshakeKeys.nonce,
                                                     launcherPublicKey, HandshakeKeys.secretKey);
    } catch(e) {
      log.error('SymmetricKey Decryption failed');
      return notifierCallback('SymmetricKey Decryption failed');
    }

    encryptionNonce = decryptedSymmKey.subarray(0, sodium.crypto_secretbox_NONCEBYTES);
    encryptionKey = decryptedSymmKey.subarray(sodium.crypto_secretbox_NONCEBYTES);
    connectionManager.setOnDataRecievedListener(onDataReceived);
    notifierCallback(null, self);
  };
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 maidsafe / safe_examples / dns_example / src / scripts / safe_api / request_manager.js View on Github external
log.warn(handshakeResponse.error);
      notifierCallback('Handshake failed - ' + handshakeResponse.error.description +
                      '(' + handshakeResponse.error.code + ')');
      return;
    }
    var launcherPublicKey = convertStringAsUnit8Array(handshakeResponse.data.launcher_public_key);
    var decryptedSymmKey;
    try {
      decryptedSymmKey = sodium.crypto_box_open_easy(convertStringAsUnit8Array(handshakeResponse.data.encrypted_symm_key), HandshakeKeys.nonce,
                                                     launcherPublicKey, HandshakeKeys.secretKey);
    } catch(e) {
      log.error('SymmetricKey Decryption failed');
      return notifierCallback('SymmetricKey Decryption failed');
    }

    encryptionNonce = decryptedSymmKey.subarray(0, sodium.crypto_secretbox_NONCEBYTES);
    encryptionKey = decryptedSymmKey.subarray(sodium.crypto_secretbox_NONCEBYTES);
    connectionManager.setOnDataRecievedListener(onDataReceived);
    notifierCallback(null, self);
  };