Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@stablelib/chacha20poly1305

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stablelib/chacha20poly1305

ChaCha20-Poly1305 AEAD (RFC 7539)

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
116K
decreased by-64.71%
Maintainers
1
Weekly downloads
 
Created

What is @stablelib/chacha20poly1305?

@stablelib/chacha20poly1305 is a JavaScript implementation of the ChaCha20-Poly1305 authenticated encryption algorithm. It is part of the StableLib collection of cryptographic libraries, which are designed to be secure, fast, and easy to use.

What are @stablelib/chacha20poly1305's main functionalities?

Encryption

This code demonstrates how to encrypt a message using the ChaCha20-Poly1305 algorithm. A 32-byte key and a 12-byte nonce are used to encrypt the message 'Hello, world!'.

const { ChaCha20Poly1305 } = require('@stablelib/chacha20poly1305');
const key = new Uint8Array(32); // 32-byte key
const nonce = new Uint8Array(12); // 12-byte nonce
const message = new TextEncoder().encode('Hello, world!');
const aead = new ChaCha20Poly1305(key);
const encrypted = aead.seal(nonce, message);
console.log(encrypted);

Decryption

This code demonstrates how to decrypt a message using the ChaCha20-Poly1305 algorithm. The same 32-byte key and 12-byte nonce used for encryption are required to decrypt the message.

const { ChaCha20Poly1305 } = require('@stablelib/chacha20poly1305');
const key = new Uint8Array(32); // 32-byte key
const nonce = new Uint8Array(12); // 12-byte nonce
const encrypted = new Uint8Array([...]); // Encrypted message
const aead = new ChaCha20Poly1305(key);
const decrypted = aead.open(nonce, encrypted);
console.log(new TextDecoder().decode(decrypted));

Authenticated Encryption with Additional Data (AEAD)

This code demonstrates how to perform authenticated encryption with additional data (AEAD) using the ChaCha20-Poly1305 algorithm. The additional data is included in the authentication process but is not encrypted.

const { ChaCha20Poly1305 } = require('@stablelib/chacha20poly1305');
const key = new Uint8Array(32); // 32-byte key
const nonce = new Uint8Array(12); // 12-byte nonce
const message = new TextEncoder().encode('Hello, world!');
const additionalData = new TextEncoder().encode('Additional data');
const aead = new ChaCha20Poly1305(key);
const encrypted = aead.seal(nonce, message, additionalData);
console.log(encrypted);

Other packages similar to @stablelib/chacha20poly1305

FAQs

Package last updated on 23 Apr 2017

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