Socket
Socket
Sign inDemoInstall

libsodium

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libsodium

The Sodium cryptographic library compiled to pure JavaScript (raw library, no wrappers)


Version published
Weekly downloads
564K
decreased by-20.16%
Maintainers
1
Weekly downloads
 
Created

What is libsodium?

libsodium is a modern, easy-to-use software library for encryption, decryption, signatures, password hashing, and more. It is designed to be a portable, cross-compilable, installable, and packageable fork of NaCl, with a compatible API.

What are libsodium's main functionalities?

Public Key Cryptography

This feature allows you to perform public key cryptography operations such as encryption and decryption. The code sample demonstrates generating a key pair, encrypting a message, and logging the ciphertext and nonce.

const sodium = require('libsodium-wrappers');
(async() => {
  await sodium.ready;
  const keyPair = sodium.crypto_box_keypair();
  const message = 'Hello, World!';
  const nonce = sodium.randombytes_buf(sodium.crypto_box_NONCEBYTES);
  const cipherText = sodium.crypto_box_easy(message, nonce, keyPair.publicKey, keyPair.privateKey);
  console.log({ cipherText, nonce });
})();

Secret Key Cryptography

This feature allows you to perform secret key cryptography operations such as encryption and decryption. The code sample demonstrates generating a key, encrypting a message, and logging the ciphertext and nonce.

const sodium = require('libsodium-wrappers');
(async() => {
  await sodium.ready;
  const key = sodium.randombytes_buf(sodium.crypto_secretbox_KEYBYTES);
  const nonce = sodium.randombytes_buf(sodium.crypto_secretbox_NONCEBYTES);
  const message = 'Hello, World!';
  const cipherText = sodium.crypto_secretbox_easy(message, nonce, key);
  console.log({ cipherText, nonce });
})();

Password Hashing

This feature allows you to hash passwords securely. The code sample demonstrates hashing a password and logging the hashed password.

const sodium = require('libsodium-wrappers');
(async() => {
  await sodium.ready;
  const password = 'mysecretpassword';
  const hashedPassword = sodium.crypto_pwhash_str(password, sodium.crypto_pwhash_OPSLIMIT_INTERACTIVE, sodium.crypto_pwhash_MEMLIMIT_INTERACTIVE);
  console.log({ hashedPassword });
})();

Digital Signatures

This feature allows you to create and verify digital signatures. The code sample demonstrates generating a key pair, signing a message, and logging the signed message.

const sodium = require('libsodium-wrappers');
(async() => {
  await sodium.ready;
  const keyPair = sodium.crypto_sign_keypair();
  const message = 'Hello, World!';
  const signedMessage = sodium.crypto_sign(message, keyPair.privateKey);
  console.log({ signedMessage });
})();

Other packages similar to libsodium

Keywords

FAQs

Package last updated on 13 Aug 2024

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