小编jia*_*ong的帖子

尝试在Cipher.update中以不受支持的状态添加数据

下面的代码正在工作

var crypto = require('crypto');
var cipher = crypto.createCipher('aes-128-cbc','abcdefghijklmnop')
var http = require('http')

var userStr = 'a134aad';
var crypted = cipher.update(userStr, 'utf8', 'hex');
crypted += cipher.final('hex');
console.log(crypted);
Run Code Online (Sandbox Code Playgroud)

但是,当将其放入服务器回调中时,它将不起作用,并且在请求到达且节点被压碎时会在err以下抛出:

http.createServer(function(req, res){
    var userStr = 'a134aad';
    var crypted = cipher.update(userStr, 'utf8', 'hex');
    crypted += cipher.final('hex');
    console.log(crypted);

    res.end('hello');
}).listen(9888)

---------------------------------

7364aee753f0568f7e5171add6868b75
crypto.js:170
  var ret = this._handle.update(data, inputEncoding);
                         ^
Error: Trying to add data in unsupported state
    at Cipher.update (crypto.js:170:26)
    at Server.<anonymous> (C:\Users\58\Desktop\sha256.js:12:26)
    at emitTwo (events.js:126:13)
    at Server.emit (events.js:214:7)
    at parserOnIncoming (_http_server.js:602:12)
    at HTTPParser.parserOnHeadersComplete …
Run Code Online (Sandbox Code Playgroud)

node.js cryptojs

2
推荐指数
2
解决办法
1346
查看次数

如何设置可写高水印?

我发现options可读流设置高水印: fs.createReadStream(path[, options])

但无法找到highwatermark options可写流

那么在创建可写流时如何设置呢?

node.js

2
推荐指数
1
解决办法
2053
查看次数

标签 统计

node.js ×2

cryptojs ×1