Socket
Socket
Sign inDemoInstall

@stablelib/chacha20poly1305

Package Overview
Dependencies
7
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @stablelib/chacha20poly1305

ChaCha20-Poly1305 AEAD (RFC 7539)


Version published
Weekly downloads
300K
increased by0.36%
Maintainers
1
Created
Weekly downloads
 

Package description

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

Last updated on 21 May 2021

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc