CRYPTO写完了

时间:2017-12-14 21:12:50

标签: javascript node.js cryptography

我有一个密码密码的功能。为此,我使用nodejs加密模块。

要进行测试,我只需复制/粘贴给定文档here

的代码
static cipherPassword(password, cb) {

    let encrypted = '';
    cipher.on('readable', () => {
      const data = cipher.read();
      if (data)
        encrypted += data.toString('hex');
    });
    cipher.on('end', () => cb(encrypted));

    cipher.write(password);
    cipher.end();

}

我遇到了错误:

  

events.js:183

     抛出错误; //未处理的'错误'事件

     

错误:写完后

我没有解决问题的方法。你能帮帮我吗?

谢谢!

编辑1.如上所述,这是一段代码,用于展示我的静态功能是如何工作的。

我的静态函数属于UserModel类

UserModel.cipherPassword('password to cipher', function(cipheredPassword) {
    // Do you whatever you wanna do with your ciphered password
});

1 个答案:

答案 0 :(得分:0)

感谢@JaromandaX,

我解决了我的问题。

像他说的那样,密码对象不能使用两次。因此,每当我调用静态函数时,我都必须重新创建它。

谢谢!