2.0.3 • Published 4 years ago
@lgslabs/bits-crypto v2.0.3
node-bits-crypto
This is a node module implementation of BITS encrypt/decrypt.
Install
npm install @lgslabs/bits-crypto
File Format
The .enc file has the following format:
UtilCrypto
const {UtilCrypto} = require('@lgslabs/bits-crypto');
Encrypt data
const {encrypt} = require('@lgslabs/bits-crypto');
const encryptionKey = getPublicEncryptionKey();
const signatureKey = getPrivateSignatureKey();
Promise.resolve()
.then(() => encrypt({
input: fs.createReadStream('data.txt'),
output: fs.createWriteStream('data.txt.enc'),
encryptionKey: encryptionKey,
signatureKey: signatureKey,
filename: 'data.txt',
})
.then((signature) => {
const output = fs.createWriteStream('data.txt.enc', {start: 0, end: 512, flags: 'r+'})
output.write(signature);
output.end();
});
Decrypt data
const {decrypt} = require('@lgslabs/bits-crypto');
const encryptionKey = getPrivateEncryptionKey();
const signatureKey = getPublicSignatureKey();
Promise.resolve()
.then(() => decrypt({
input: fs.createReadStream('data.txt.enc'),
output: fs.createWriteStream('data.txt'),
encryptionKey: encryptionKey,
signatureKey: signatureKey,
});
CLI
This module also provides two scripts to encrypt and decrypt data from the command line. See the help for command details.
npm install -g @lgslabs/bits-crypto
encrypt-data -t data.txt -e foo-key.pub -s mine-key.pem
decrypt-data -t data.enc -e foo-key.pem -s mine-key.pub