Coder Social home page Coder Social logo

file-encryptor's Introduction

file-encryptor

Encrypts files using Node's built-in Cipher class. Encryption is stream-based for low memory footprint.

Getting Started

Install the module:

npm install file-encryptor

Use it in your script:

var encryptor = require('file-encryptor');

var key = 'My Super Secret Key';

// Encrypt file.
encryptor.encryptFile('input_file.txt', 'encrypted.dat', key, function(err) {
  // Encryption complete.
});

...

// Decrypt file.
encryptor.decryptFile('encrypted.dat', 'output_file.txt', key, function(err) {
  // Decryption complete.
});

The input file will be streamed through the Cipher and to the output file. If the output files does not exists, it will be created. If the output file already exists, it will be truncated.

Change Cipher Algorithm

By default the "aes192" cipher algorithm is used. This can be changed by passing a new algorithm string as an option.

Available algorithms can be found by executing:

openssl list-cipher-algorithms

Setting algorithm option:

var key = 'My Super Secret Key';
var options = { algorithm: 'aes256' };

encryptor.encryptFile('input_file.txt', 'encrypted.dat', key, options, function(err) {
  // Decryption complete;
});

...

encryptor.decryptFile('encrypted.dat', 'outputfile.txt', key, options, function(err) {
  // Encryption complete;
});

License

Copyright (c) 2013 Modulus Licensed under the MIT license.

file-encryptor's People

Contributors

hisankaran avatar inconceivableduck avatar tzmanics avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

file-encryptor's Issues

Needs to be updated

I get warning as follows:

(node:77708) [DEP0106] DeprecationWarning: crypto.createCipher is deprecated.
(Use node --trace-deprecation ... to show where the warning was created)

Error decrypting

Hi!

I am getting this error when I try to decrypt a file. I am using your example. Any help will be appreciated.

Thanks!

crypto.js:292
var ret = this._binding.final();
^
TypeError: error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length
at Decipher.Cipher.final (crypto.js:292:27)
at ReadStream. (/home/j/lab/node_modules/file-encryptor/lib/file-encryptor.js:57:33)
at ReadStream.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:920:16
at process._tickCallback (node.js:415:13)

Delete Source after decryption

I think a handy feature would be to keep a flag which determines the deletion of the encrypted file after successful decryption

Decrypt output with openssl

I'm wondering how to decrypt an output file by external means.

I encrypted my file with aes256 and the password foo. I then tried to use openssl enc -aes256 -d -in encrypted.dat -out output_file.txt -k foo.

It just gives me the error bad magic number. What am I doing wrong?

Decrypting with file-encryptor.decryptFile works fine.

Application crashes if wrong key is passed to decryptFile()

I manually commented out line 70 i.e. fs.unlink(outputPath); in lib/file-encryptor.js and the application doesn't crash after that. I think it is not able to unlink (delete) the file due to some reason.

NOTE: This only happens when invalid key is passed to the decryptFile() function.
Check the attached screenshot (from my heroku console)

error

encryptFileSync

Hi,

do you have a encryptFile which waits for the file to be processed?
it would be very helpful..

Uncaught Error: EMFILE: too many open files, open

Hello All.

     I am trying to encrypt almost 10000+ file in a row using following function.
     It gives error something like:
     ## Uncaught Error: EMFILE: too many open files, open 'bun.ogg' 

Source code is given bellow.

     function copyRecursiveSync(src, dest) {
var exists = fs.existsSync(src);
var stats = exists && fs.statSync(src);
var unSelectedArray = getUnSelectedOptionArray();
var isDirectory = exists && stats.isDirectory();
if (exists && isDirectory) {
    var destExist = fs.existsSync(dest);
    if (!destExist)
        fs.mkdirSync(dest);
    fs.readdirSync(src).forEach(function (childItemName) {
        copyRecursiveSync(path.join(src, childItemName),
            path.join(dest, childItemName));
    });
} else {

    var splitArray = src.split(".");

    if (isFileEncrypt(splitArray[1], unSelectedArray) === true) {
        encryptor.encryptFile(src, dest, secrateKey, options, function (err) {});

    } else {
        fs.linkSync(src, dest);
    }
}

}

Please help me to solve this. I am very new in this technology.
     Any Other solution for doing this is also excepted. 

Can not decrypt

Same problem here : #6

Hey hi, I have a problem to decrypt my archive. The archive works normally.

CODE :

// Get modules
const fs    = require('fs');
const crypt = require('file-encryptor');

// Set key
const key = '256_CHARACTERS_UTF8';

// Encrypt archive
crypt.encryptFile('my_archive_3MB.tar.gz', 'my_archive_3MB.tar.gz.crypt', key, { algorithm: 'aes256' }, (err)=>
{
	// Decrypt archive
	crypt.decryptFile('my_archive_3MB.tar.gz.crypt', 'my_archive_3MB.tar.gz', key, { algorithm: 'aes256' }, (err)=>
	{
		console.log(err);
	});
});

EXECUTE FILE IN CONSOLE :

Error: error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length
    at Decipher.final (crypto.js:158:26)
    at ReadStream.<anonymous> (/Users/cedric/Developer/research/kordacloud/backuper/node_modules/file-encryptor/lib/file-encryptor.js:63:35)
    at emitNone (events.js:91:20)
    at ReadStream.emit (events.js:188:7)
    at endReadableNT (_stream_readable.js:975:12)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)
(node:7968) DeprecationWarning: Calling an asynchronous function without callback is deprecated.

Decryption is not working on linux environment

Encryption works and decryption also gets completed but gets corrupted file with some less size as compare to original On windows 10 it works.

var encryptor = require('file-encryptor')
var key = '123';
var options = { algorithm: 'aes256' };

encryptor.encryptFile('project/assets/MIHQM16FMSQ811TS2111.mp4', 'project/assets/MIHQM16FMSQ811TS2111Encrypted.dat', key, function(err) {

});

encryptor.decryptFile('project/assets/MIHQM16FMSQ811TS2111Encrypted.dat', 'project/assets/MIHQM16FMSQ811TS2111Decrypted.mp4', key, function(err) {
console.log('Decryption complete');
});

fs.js:165 Uncaught NodeError: Callback must be a function

Hi! first of all, thanks!

I'm using Node 86. I'm not quite sure at which version this started happening, but not fs.unlink is obligated to have a callback. This is causing an error:

fs.js:165 Uncaught NodeError: Callback must be a function
   at ReadStream.<anonymous> (/.../file-encryptor.js:70:10)

which makes your decrypting package fail. I can look into this if you like.
Thanks again!

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.