
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
encryptedfs
Advanced tools
Encrypted filesystem library for TypeScript/JavaScript applications
Development based on js-virtualfs: https://github.com/MatrixAI/js-virtualfs
npm install --save encryptedfs
import type { EFSWorkerModule } from 'encryptedfs';
import { WorkerManager } from '@matrixai/workers';
import { EncryptedFS, utils } from 'encryptedfs';
const key = utils.generateKeySync(256);
const efs = await EncryptedFS.createEncryptedFS({
dbPath: '/tmp/efs',
dbKey: key,
});
// optionally set up the worker manager for multi-threaded encryption/decryption
const workerManager = await WorkerManager.createWorkerManager<EFSWorkerModule>({
workerFactory: () => spawn(new Worker('./src/workers/efsWorker'))
});
efs.setWorkerManager(workerManager);
// create a new directory
const newDir = `test`;
await efs.mkdir(newDir);
// write out to a file
await efs.writeFile(`${newDir}/testFile`, 'output');
// read in the file (contents = 'output')
const contents = await efs.readFile(`${newDir}/testFile`);
// closes the EFS
await efs.stop();
// destroys the EFS state
await efs.destroy();
Encryption & Decryption implemented using the node-forge
library. However it is possible to plug in your own encrypt
and decrypt
functions.
Internally we use the AES-GCM symmetric encryption using a master dbKey
that can be 128, 192 or 256 bits long.
The dbKey
can be generated from several methods:
generateKey
- random asynchronousgenerateKeySync
- random synchronousgenerateKeyFromPass
- derived from user-provided "password" asynchronousgenerateKeyFromPassSync
- derived from user-provided "password" synchronousFor example:
const [key, salt] = await generateKeyFromPass('secure password');
This uses PBKDF2 to derive a symmetric key. The default key length will be 256 bits. For deterministic key generation, make sure to specify the salt
parameter.
const [key, salt] = await generateKeyFromPass('secure password', 'salt');
Construction of EncryptedFS
relies on an optional blockSize
parameter. This is by default set to 4 KiB. All files are broken up into 4 KiB plaintext blocks. When encrypted, they are persisted as ciphertext blocks.
The ciphertext blocks contain an initialization vector plus an authorisation tag. Here is an example of the structure:
| iv (16 bytes) | authTag (16 bytes) | ciphertext data (x bytes) |
The ciphertext data length is equal to the plaintext block length.
There are some differences between EFS and Node FS:
Run nix develop
, and once you're inside, you can use:
# install (or reinstall packages from package.json)
npm install
# build the dist
npm run build
# run the repl (this allows you to import from ./src)
npm run tsx
# run the tests
npm run test
# lint the source code
npm run lint
# automatically fix the source
npm run lintfix
npm run bench
View benchmarks here: https://github.com/MatrixAI/js-encryptedfs/blob/master/benches/results with https://raw.githack.com/
npm run docs
See the docs at: https://matrixai.github.io/js-encryptedfs/
Publishing is handled automatically by the staging pipeline.
Prerelease:
# npm login
npm version prepatch --preid alpha # premajor/preminor/prepatch
git push --follow-tags
Release:
# npm login
npm version patch # major/minor/patch
git push --follow-tags
Manually:
# npm login
npm version patch # major/minor/patch
npm run build
npm publish --access public
git push
git push --tags
FAQs
Virtualised persistent encrypted filesystem
The npm package encryptedfs receives a total of 326 weekly downloads. As such, encryptedfs popularity was classified as not popular.
We found that encryptedfs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
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.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.