Streaming AES-CTR for node and browsers
npm install @libp2p/aes-ctr



> Streaming AES-CTR for node and browsers
WebCrypto does not support streaming encryption -
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.
``js
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:
// Decrypting
const decipher = create(key128, IV)
const decryptedBuffer = decipher.decrypt(encryptedBuffer)
console.log(decryptedBuffer)
// prints:
console.log(decryptedBuffer.toString('utf-8'))
// prints: Hello, world!
`
`console`
$ npm i @libp2p/aes-ctr
-
Licensed under either of
- Apache 2.0, (LICENSE-APACHE /
- MIT (LICENSE-MIT /
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.