mirror of
https://framagit.org/hubzilla/core.git
synced 2026-06-21 00:52:33 -04:00
1.4 KiB
1.4 KiB
Sealed boxes
See also: Libsodium's documentation on its sealed boxes features.
crypto_box_seal
Anonymous public-key encryption. (Message integrity is still assured.)
Parameters and their respective types:
{string|Buffer}plaintext{X25519PublicKey}public key
Returns a Promise that resolves to a Buffer.
crypto_box_seal_open
Anonymous public-key decryption. (Message integrity is still assured.)
Parameters and their respective types:
{Buffer}ciphertext{X25519PublicKey}public key{X25519SecretKey}secret key
Returns a Promise that resolves to a Buffer.
Example for crypto_box_seal
const { SodiumPlus } = require('sodium-plus');
let sodium;
(async function () {
if (!sodium) sodium = await SodiumPlus.auto();
let aliceKeypair = await sodium.crypto_box_keypair();
let aliceSecret = await sodium.crypto_box_secretkey(aliceKeypair);
let alicePublic = await sodium.crypto_box_publickey(aliceKeypair);
let plaintext = 'Your message goes here';
let ciphertext = await sodium.crypto_box_seal(plaintext, alicePublic);
console.log(ciphertext);
let decrypted = await sodium.crypto_box_seal_open(ciphertext, alicePublic, aliceSecret);
console.log(decrypted.toString());
})();