Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cfal/aes-cbc-stream
nodejs module for AES-CBC stream encryption and decryption, with support for partial decryption.
https://github.com/cfal/aes-cbc-stream
Last synced: 23 days ago
JSON representation
nodejs module for AES-CBC stream encryption and decryption, with support for partial decryption.
- Host: GitHub
- URL: https://github.com/cfal/aes-cbc-stream
- Owner: cfal
- License: mit
- Created: 2021-01-01T08:58:09.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-01-01T09:13:40.000Z (almost 4 years ago)
- Last Synced: 2024-11-19T04:11:48.722Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 30.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# aes-cbc-stream
nodejs module for AES-CBC stream encryption and decryption, with support for partial decrypts.
# Installation
`npm install aes-cbc-stream`
# Examples
### Encrypt a file
```
const fs = require('fs'),
crypto = require('crypto');
const { EncryptStream } = require('aes-cbc-stream')// Encrypt `data.bin`.
const inputStream = fs.createReadStream('data.bin');
const outputStream = fs.createWriteStream('encrypted.bin');const encryptKey = crypto.randomBytes(32);
inputStream
.pipe(new EncryptStream({
key: encryptKey,
cipherName: 'aes-256-cbc'
}))
.pipe(outputStream);
outputStream.on('finish', function() {
console.log("File encrypted!");
});
```### Partially decrypt a file
```
const fs = require('fs'),
crypto = require('crypto');// The desired range (inclusive) of decrypted data.
const start = 100, end = 300;// Find the parameters to pass to DecryptStream with calculateParams().
const {
skipPrefixLength,
encryptedStartIndex,
encryptedEndIndex,
wantedOutputLength
} = DecryptStream.calculateParams({
decryptedStartIndex: start,
decryptedEndIndex: end
});const inputStream = fs.createReadStream('encrypted.bin');
const outputStream = fs.createWriteStream('decrypted.bin');const decryptStream = new DecryptStream({
// The key and cipher used to encrypt the file from the previous example.
key: encryptKey,
cipherName: 'aes-256-cbc',
// Start and end index at block boundaries, with a preceding IV block.
encryptedStartIndex,
encryptedEndIndex,// The number of initial decrypted bytes to skip. If `start` does not
// start at a block boundary, this is a non-zero number in order to
// return the requested range.
skipPrefixLength,
// The desired output length.
wantedOutputLength
});inputStream.pipe(decryptStream)
.pipe(outputStream);
outputStream.on('finish', () => {
console.log("Decryption done!");
});
```