Skip to content
This repository was archived by the owner on Jun 14, 2018. It is now read-only.
This repository was archived by the owner on Jun 14, 2018. It is now read-only.

Decrypt fails after one succesful encryption and decryption #9

@ysk8

Description

@ysk8

When the user try to authenticate the first time and fail/success, then, try again/logout, the server is stopped and throw this error:

crypto.js:279
var ret = this._binding.update(data, inputEncoding);
^
TypeError: error:00000000:lib(0):func(0):reason(0)
at Decipher.Cipher.update (crypto.js:279:27)

All function well each time restart the app.

The Code:

var algorithm = 'aes-256-cbc';
var inputEncoding = 'utf8';
var outputEncoding = 'hex';

var crypto = require('crypto'),
key = process.env.SUPER_SECRET_KEY,
cipher = crypto.createCipher(algorithm, key),
decipher = crypto.createDecipher(algorithm, key);

exports.cipherData = function(pass){
var encryptedPass = cipher.update(pass, inputEncoding, outputEncoding);
encryptedPass += cipher.final(outputEncoding);

return encryptedPass;

}

exports.decipherData = function(pass){
var decryptedPass = decipher.update(pass, outputEncoding, inputEncoding);
decryptedPass += decipher.final(inputEncoding);
console.log(decryptedPass);

return decryptedPass;

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions