Skip to content

Instantly share code, notes, and snippets.

@bennycode
Last active February 15, 2018 14:22
Show Gist options
  • Save bennycode/34e69e243bb190cc2c1bad969f0f5089 to your computer and use it in GitHub Desktop.
Save bennycode/34e69e243bb190cc2c1bad969f0f5089 to your computer and use it in GitHub Desktop.
Working with libsodium.js v0.7.3
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