1.0.0 • Published 4 months ago

@libp2p/aes-ctr v1.0.0

Weekly downloads
-
License
Apache-2.0 OR MIT
Repository
github
Last release
4 months ago

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.

1.0.0

4 months ago

0.0.0

4 months ago