New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@libp2p/aes-ctr

Package Overview
Dependencies
Maintainers
6
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@libp2p/aes-ctr

Streaming AES-CTR for node and browsers

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
6
Created
Source

libp2p.io Discuss codecov CI

Streaming AES-CTR for node and browsers

About

WebCrypto does not support streaming encryption - https://github.com/w3c/webcrypto/issues/73

In browsers this module uses node-forge to expose a streaming interface to AES encryption (formerly Rijndael), as defined in U.S. Federal Information Processing Standards Publication 197.

In node.js it uses the regular streaming API exported by the crypto module.

This uses CTR mode.

Example

import { create } from '@libp2p/aes-ctr'

// Setting up Key and IV

// A 16 bytes array, 128 Bits, AES-128 is chosen
const key128 = Uint8Array.from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])

// A 16 bytes array, 128 Bits,
const IV = Uint8Array.from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])

const decryptedMessage = 'Hello, world!'

// Encrypting
const cipher = create(key128, IV)
const encryptedBuffer = cipher.encrypt(Uint8Array.from(decryptedMessage))
console.log(encryptedBuffer)
// prints: <Uint8Array 42 f1 67 d9 2e 42 d0 32 9e b1 f8 3c>

// Decrypting
const decipher = create(key128, IV)
const decryptedBuffer = decipher.decrypt(encryptedBuffer)

console.log(decryptedBuffer)
// prints: <Uint8Array 42 f1 67 d9 2e 42 d0 32 9e b1 f8 3c>

console.log(decryptedBuffer.toString('utf-8'))
// prints: Hello, world!

Install

$ npm i @libp2p/aes-ctr

Browser <script> tag

Loading this module through a script tag will make it's exports available as Libp2pAesCtr in the global namespace.

<script src="https://unpkg.com/@libp2p/aes-ctr/dist/index.min.js"></script>

API Docs

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Keywords

FAQs

Package last updated on 12 Jan 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