Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
encrypt(plaintext: string | Uint8Array, nonce: Uint8Array): Uint8Array {
// TODO: Re-validate if the ArrayBuffer check is needed (Prerequisite: Integration tests)
if (plaintext instanceof ArrayBuffer && plaintext.byteLength !== undefined) {
plaintext = new Uint8Array(plaintext);
}
return sodium.crypto_stream_chacha20_xor(plaintext, nonce, this.key, 'uint8array');
}
encrypt(plaintext: string | Uint8Array, nonce: Uint8Array): Uint8Array {
// TODO: Re-validate if the ArrayBuffer check is needed (Prerequisite: Integration tests)
if (plaintext instanceof ArrayBuffer && plaintext.byteLength !== undefined) {
plaintext = new Uint8Array(plaintext);
}
return sodium.crypto_stream_chacha20_xor(plaintext, nonce, this.key, 'uint8array');
}