Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 23 additions & 30 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,21 +207,16 @@ Blind.prototype.encrypt = function(data, key) {

// encrypt the data

try {
var cipher = crypto.createCipher(self.encryptAlgorithm, key);
var buffers = [];

cipher.on('data', function (chunk) {
buffers.push(chunk);
})
.on('end', function () {
resolve(Buffer.concat(buffers).toString(self.binaryEncoding));
})
.end(data, stringEncoding);
}
catch (error) {
reject(error);
}
var cipher = crypto.createCipher(self.encryptAlgorithm, key);
var buffers = [];

cipher.on('data', function (chunk) {
buffers.push(chunk);
})
.on('end', function () {
resolve(Buffer.concat(buffers).toString(self.binaryEncoding));
})
.end(data, stringEncoding);
});
};

Expand Down Expand Up @@ -281,22 +276,20 @@ Blind.prototype.decrypt = function(data, key) {

// decrypt the data

try {
var decipher = crypto.createDecipher(self.encryptAlgorithm, key);
var buffers = [];

decipher.on('data', function (chunk) {
buffers.push(chunk);
})
.on('end', function () {
resolve(Buffer.concat(buffers).toString(stringEncoding));
})
.end(data, self.binaryEncoding);
}
catch (error) {

var decipher = crypto.createDecipher(self.encryptAlgorithm, key);
var buffers = [];

decipher.on('data', function (chunk) {
buffers.push(chunk);
})
.on('end', function () {
resolve(Buffer.concat(buffers).toString(stringEncoding));
}).on('error', function () {
reject(new Error('Could not decrypt data; \'data\' may not be encrypted ' +
' or may not have been encrypted with \'key\''));
}
' or may not have been encrypted with \'key\''));
})
.end(data, self.binaryEncoding);
});
};

Expand Down