Giter VIP home page Giter VIP logo

folder-encrypt's Introduction

folder-encrypt

Simple module that helps you encrypt & decrypt folder/file with password.

Installation

npm i folder-encrypt

Usage

Both methods (encrypt, decrypt) of folder-encrypt use Promise, and it will automatically detect whether this path is a file or directory.

Folder/File Encryption

import * as folderEncrypt from 'folder-encrypt';

folderEncrypt.encrypt({
    password: 'your-password',
    input: 'your-file-or-folder',
    output: 'your-file-or-folder.encrypted' // optional, default will be input path with extension `encrypted`
}).then(() => {
    console.log('encrypted!');
}).catch((err) => {
    console.log(err);
});

Stream as Output

import * as folderEncrypt from 'folder-encrypt';
import { Writable } from 'stream';
import * as fs from 'fs';

const outputs = [
    fs.createWriteStream('./output1'),
    fs.createWriteStream('./output2')
], writeStream = new Writable({
    write(chunk, encoding, next) {
        for (let i = outputs.length; i--;)  outputs[i].write(chunk);
        next();
    }
});

folderEncrypt.encrypt({
    password: 'your-password',
    input: 'your-file-or-folder',
    output: writeStream // writable stream
}).then(() => {
    console.log('encrypted!');
}).catch((err) => {
    console.log(err)
});

Folder/File Decryption

folderEncrypt.decrypt({
    password: 'your-password',
    input: 'your-file-or-folder.encrypted',
    output: 'your-file-or-folder' // optional, default will be input path without extension
}).then(() => {
    console.log('decrypted!');
    // when using a wrong password on file decryption, the file will be decrypted to a bunch of garbled text. 
    // But still considered `decrypted` due to there is no way knowing the original content.
}).catch((err) => {
    console.log(err); 
    // when using a wrong password on directory decryption, a `tar is corrupted` error will occured.
});

folder-encrypt's People

Contributors

scrwdrv avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.