Socket
Socket
Sign inDemoInstall

libsodium-wrappers

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libsodium-wrappers

The Sodium cryptographic library compiled to pure JavaScript (wrappers)


Version published
Weekly downloads
668K
decreased by-9.3%
Maintainers
1
Weekly downloads
 
Created

What is libsodium-wrappers?

libsodium-wrappers is a JavaScript wrapper for the Sodium cryptographic library, providing a wide range of cryptographic operations including encryption, decryption, hashing, and key generation. It is designed to be easy to use and secure, making it suitable for both beginners and advanced users.

What are libsodium-wrappers's main functionalities?

Encryption and Decryption

This feature allows you to encrypt and decrypt messages using secret-key cryptography. The code sample demonstrates generating a key and nonce, encrypting a message, and then decrypting it back to its original form.

const sodium = require('libsodium-wrappers');
(async() => {
  await sodium.ready;
  const key = sodium.crypto_secretbox_keygen();
  const nonce = sodium.randombytes_buf(sodium.crypto_secretbox_NONCEBYTES);
  const message = 'Hello, World!';
  const ciphertext = sodium.crypto_secretbox_easy(message, nonce, key);
  const decrypted = sodium.crypto_secretbox_open_easy(ciphertext, nonce, key);
  console.log(sodium.to_string(decrypted)); // 'Hello, World!'
})();

Hashing

This feature provides hashing capabilities. The code sample shows how to hash a message using the crypto_generichash function and then convert the hash to a hexadecimal string.

const sodium = require('libsodium-wrappers');
(async() => {
  await sodium.ready;
  const message = 'Hello, World!';
  const hash = sodium.crypto_generichash(32, message);
  console.log(sodium.to_hex(hash));
})();

Key Generation

This feature allows you to generate public and private key pairs. The code sample demonstrates generating a key pair and printing the public and private keys in hexadecimal format.

const sodium = require('libsodium-wrappers');
(async() => {
  await sodium.ready;
  const keyPair = sodium.crypto_box_keypair();
  console.log(sodium.to_hex(keyPair.publicKey));
  console.log(sodium.to_hex(keyPair.privateKey));
})();

Other packages similar to libsodium-wrappers

Keywords

FAQs

Package last updated on 20 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc