diff options
author | Mario <mario@mariovavti.com> | 2024-03-22 08:37:29 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2024-03-22 08:37:29 +0000 |
commit | 1aeb05628b6a2a069c46980efbe628362c9e3e74 (patch) | |
tree | e9aed15d0cd74e0c23dcb05c7be8fe9541efdf36 /library/sodium-plus/docs/SodiumPlus/shared-key-authenticated-encryption.md | |
parent | 5b7387459cf4de8f7354d81cb0392c4225714d94 (diff) | |
parent | b464fae3bf22585888c5f3def8eded76fd48ed16 (diff) | |
download | volse-hubzilla-9.0.tar.gz volse-hubzilla-9.0.tar.bz2 volse-hubzilla-9.0.zip |
Merge branch '9.0RC'9.0
Diffstat (limited to 'library/sodium-plus/docs/SodiumPlus/shared-key-authenticated-encryption.md')
-rw-r--r-- | library/sodium-plus/docs/SodiumPlus/shared-key-authenticated-encryption.md | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/library/sodium-plus/docs/SodiumPlus/shared-key-authenticated-encryption.md b/library/sodium-plus/docs/SodiumPlus/shared-key-authenticated-encryption.md new file mode 100644 index 000000000..688570933 --- /dev/null +++ b/library/sodium-plus/docs/SodiumPlus/shared-key-authenticated-encryption.md @@ -0,0 +1,62 @@ +## Shared-key authenticated encryption + +> **See also**: [Libsodium's documentation on its shared-key authenticated encryption features](https://download.libsodium.org/doc/secret-key_cryptography/secretbox). + +### crypto_secretbox + +Shared-key authenticated encryption. + +**Parameters and their respective types**: + +1. `{string|Buffer}` Plaintext +2. `{string|Buffer}` nonce (must be 24 bytes) +3. `{CryptographyKey}` key + +Returns a `Promise` that resolves to a `Buffer`. + +### crypto_secretbox_open + +Shared-key authenticated decryption. + +**Parameters and their respective types**: + +1. `{string|Buffer}` Ciphertext +2. `{string|Buffer}` nonce (must be 24 bytes) +3. `{CryptographyKey}` key + +Returns a `Promise` that resolves to a `Buffer`. +Throws a `SodiumError` on decryption failure. + +### crypto_secretbox_keygen + +Returns a `CryptographyKey` object containing a key appropriate +for the `crypto_secretbox` API. + +### Example for crypto_secretbox + +```javascript +const { SodiumPlus } = require('sodium-plus'); +let sodium; + +(async function () { + if (!sodium) sodium = await SodiumPlus.auto(); + let plaintext = 'Your message goes here'; + let key = await sodium.crypto_secretbox_keygen(); + let nonce = await sodium.randombytes_buf(24); + let ciphertext = await sodium.crypto_secretbox( + plaintext, + nonce, + key + ); + + console.log(ciphertext.toString('hex')); + + let decrypted = await sodium.crypto_secretbox_open( + ciphertext, + nonce, + key + ); + + console.log(decrypted.toString()); +})(); +``` |