aboutsummaryrefslogtreecommitdiffstats
path: root/library/sodium-plus/docs/SodiumPlus/one-time-authentication.md
blob: 16c11d0c88b00af511803dded5877206f69a0ffe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
## One-time authentication

> **See also**: [Libsodium's documentation on its one-time authentication features](https://download.libsodium.org/doc/advanced/poly1305).

### crypto_onetimeauth

Get an authenticator for a message for a given key.

**Important:** In order to be secure, keys must be:

1. Secret.
2. Unpredictable.
3. Unique.

**Parameters and their respective types**:

1. `{string|Buffer}` message
2. `{CryptographyKey}` key

Return a `Promise` that resolves to a `Buffer`.

### crypto_onetimeauth_verify

Verify an authenticator for a message for a given key.

**Parameters and their respective types**:

1. `{string|Buffer}` message
2. `{CryptographyKey}` key
2. `{Buffer}` tag

Return a `Promise` that resolves to a `boolean`.

### crypto_onetimeauth_keygen

Returns a `CryptographyKey` object containing a key appropriate
for the `crypto_auth` API.

### Example for crypto_onetimeauth

```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_onetimeauth_keygen();
    let tag = await sodium.crypto_onetimeauth(plaintext, key);
    console.log(await sodium.crypto_onetimeauth_verify(plaintext, key, tag));
})();
```