I'm encrypting/decrypting a string using the following functions:
function encrypt(text, pswrd){
  var cipher = crypto.createCipher(algorithm,pswrd),
      crypted = cipher.update(text,'utf8','hex');
      crypted += cipher.final('hex');
  return crypted;
}
function decrypt(text, pswrd){
  var decipher = crypto.createDecipher(algorithm,pswrd),
      dec = decipher.update(text,'hex','utf8');
      dec += decipher.final('utf8');
  return dec;
}
The password is being asked using inquirer, so the user input a password to encrypt and then should use the same to decrypt.
Everything works while the password matches, but the problem is when the password is wrong. I can't find a callback/method to handle the error that the console outputs then a decryption fails because of the wrong password. the terminal shows:
? Use same password: *
p�pP��X�B
��=�a�_��b��EyX��7�����X�y�����+�Rr�<��΅W��B�������am4r���+��v�
readline.js:924
            throw err;
            ^
SyntaxError: Unexpected token 
    at Object.parse (native)
How can I handle this error when a wrong password is used to decrypt?
 
     
    