blob: 43d493b8826ff926d4412610a98ab3283c2c1074 (
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
|
## Utilities
### sodium_bin2hex
Encode data into a hexadecimal string.
**Parameters and their respective types**:
1. `{string|Buffer}` non-hex-encoded input
Returns a `Promise` that resolves to a `string`.
```javascript
const { SodiumPlus } = require('sodium-plus');
let sodium;
(async function () {
if (!sodium) sodium = await SodiumPlus.auto();
let buf = await sodium.randombytes_buf(32);
console.log(await sodium.sodium_bin2hex(buf));
})();
```
### sodium_hex2bin
Decode data from a hexadecimal string to a `Buffer`.
**Parameters and their respective types**:
1. `{string|Buffer}` hex-encoded input
Returns a `Promise` that resolves to a `Buffer`.
```javascript
const { SodiumPlus } = require('sodium-plus');
let sodium;
(async function () {
if (!sodium) sodium = await SodiumPlus.auto();
let hex = '491d40c4924ba547d6f0bda9da77a539391decdc';
console.log(await sodium.sodium_hex2bin(hex));
})();
```
|