Last active
February 15, 2018 14:22
-
-
Save bennycode/34e69e243bb190cc2c1bad969f0f5089 to your computer and use it in GitHub Desktop.
Working with libsodium.js v0.7.3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const _sodium = require('libsodium-wrappers-sumo'); | |
(async () => { | |
await _sodium.ready; | |
const sodium = _sodium; | |
console.log(sodium.from_base64('SGVsbG8=', sodium.base64_variants.ORIGINAL)); // Uint8Array(5) [72, 101, 108, 108, 111] | |
console.log(sodium.from_hex('48656c6c6f')); // Uint8Array(5) [72, 101, 108, 108, 111] | |
console.log(sodium.from_string('Hello')); // Uint8Array(5) [72, 101, 108, 108, 111] | |
console.log(sodium.to_base64(new Uint8Array([72, 101, 108, 108, 111]), sodium.base64_variants.ORIGINAL)); // "SGVsbG8=" | |
console.log(sodium.to_hex(new Uint8Array([72, 101, 108, 108, 111]))); // "48656c6c6f" | |
console.log(sodium.to_string(new Uint8Array([72, 101, 108, 108, 111]))); // "Hello" | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment