mirror of
https://framagit.org/hubzilla/core.git
synced 2026-06-21 00:52:33 -04:00
1.2 KiB
1.2 KiB
Shared-key authentication
See also: Libsodium's documentation on its shared-key authentication features.
crypto_auth
Get an authenticator for a message for a given key.
Parameters and their respective types:
{string|Buffer}message{CryptographyKey}key
Return a Promise that resolves to a Buffer.
crypto_auth_verify
Verify an authenticator for a message for a given key.
Parameters and their respective types:
{string|Buffer}message{CryptographyKey}key{Buffer}mac
Return a Promise that resolves to a boolean.
crypto_auth_keygen
Returns a CryptographyKey object containing a key appropriate
for the crypto_auth API.
Example for crypto_auth
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_auth_keygen();
let mac = await sodium.crypto_auth(plaintext, key);
console.log(await sodium.crypto_auth_verify(plaintext, key, mac));
})();