mirror of
https://framagit.org/hubzilla/core.git
synced 2026-06-21 00:52:33 -04:00
943 B
943 B
Utilities
sodium_bin2hex
Encode data into a hexadecimal string.
Parameters and their respective types:
{string|Buffer}non-hex-encoded input
Returns a Promise that resolves to a string.
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:
{string|Buffer}hex-encoded input
Returns a Promise that resolves to a Buffer.
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));
})();