Socket
Socket
Sign inDemoInstall

tweetnacl

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tweetnacl

Port of TweetNaCl cryptographic library to JavaScript


Version published
Weekly downloads
20M
increased by0.61%
Maintainers
1
Weekly downloads
 
Created

What is tweetnacl?

The tweetnacl npm package is a port of NaCl, the Networking and Cryptography library, to JavaScript. It provides a set of cryptographic primitives for encryption, decryption, signing, and verification. It is designed to be easy to use and to have a high level of security.

What are tweetnacl's main functionalities?

Public-key authenticated encryption

This feature allows for secure message exchange between two parties using public-key cryptography. The code sample demonstrates how to encrypt and decrypt a message using a pair of public and private keys.

const nacl = require('tweetnacl');
const naclUtil = require('tweetnacl-util');

const keyPairA = nacl.box.keyPair();
const keyPairB = nacl.box.keyPair();

const nonce = nacl.randomBytes(nacl.box.nonceLength);
const message = naclUtil.decodeUTF8('Secret Message');

const encrypted = nacl.box(message, nonce, keyPairB.publicKey, keyPairA.secretKey);

const decrypted = nacl.box.open(encrypted, nonce, keyPairA.publicKey, keyPairB.secretKey);

const decryptedMessage = naclUtil.encodeUTF8(decrypted);

Secret-key authenticated encryption

This feature provides a way to encrypt and decrypt messages using a shared secret key. The code sample shows how to perform authenticated encryption and decryption with a nonce and a single key.

const nacl = require('tweetnacl');
const naclUtil = require('tweetnacl-util');

const secretKey = nacl.randomBytes(nacl.secretbox.keyLength);
const nonce = nacl.randomBytes(nacl.secretbox.nonceLength);
const message = naclUtil.decodeUTF8('Secret Message');

const encrypted = nacl.secretbox(message, nonce, secretKey);

const decrypted = nacl.secretbox.open(encrypted, nonce, secretKey);

const decryptedMessage = naclUtil.encodeUTF8(decrypted);

Digital signatures

This feature allows for the creation and verification of digital signatures. The code sample demonstrates how to sign a message and verify the signature using a public and private key pair.

const nacl = require('tweetnacl');
const naclUtil = require('tweetnacl-util');

const keyPair = nacl.sign.keyPair();
const message = naclUtil.decodeUTF8('Verify this message');

const signature = nacl.sign.detached(message, keyPair.secretKey);

const isVerified = nacl.sign.detached.verify(message, signature, keyPair.publicKey);

Hashing

This feature provides a way to compute a cryptographic hash of a message. The code sample shows how to hash a message and encode the hash in base64.

const nacl = require('tweetnacl');
const naclUtil = require('tweetnacl-util');

const message = naclUtil.decodeUTF8('Hash this message');
const hash = nacl.hash(message);

const hashHex = naclUtil.encodeBase64(hash);

Other packages similar to tweetnacl

Keywords

FAQs

Package last updated on 13 Dec 2016

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