blob: 54c910afe9befbc5d794ded24a309baf730f69ea (
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
|
## Short-input hashing
> **See also**: [Libsodium's documentation on its short-input hashing features](https://download.libsodium.org/doc/hashing/short-input_hashing).
### crypto_shorthash
Calculate a fast hash for short inputs.
**Parameters and their respective types**:
1. `{string|Buffer}` input
3. `{CryptographyKey}` key
Returns a `Promise` that resolves to a `Buffer`.
### crypto_shorthash_keygen
Returns a `CryptographyKey` object containing a key appropriate
for the `crypto_shorthash` API.
### Example for crypto_shorthash
> **Warning:** You probably want [`crypto_generichash()`](general-purpose-cryptographic-hash.md)
> for most use-cases. `crypto_shorthash()` does not offer collision resistance.
```javascript
const { SodiumPlus } = require('sodium-plus');
let sodium;
(async function () {
if (!sodium) sodium = await SodiumPlus.auto();
let key = await sodium.crypto_shorthash_keygen();
let mapped = {};
mapped['foo'] = (await sodium.crypto_shorthash('foo', key)).toString('hex');
mapped['bar'] = (await sodium.crypto_shorthash('bar', key)).toString('hex');
mapped['baz'] = (await sodium.crypto_shorthash('baz', key)).toString('hex');
console.log(mapped);
})();
```
|