尝试在Cipher.update中以不受支持的状态添加数据 [英] Trying to add data in unsupported state at Cipher.update
本文介绍了尝试在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);
但是当放入服务器回调时,它将不起作用,并且在请求到达时会在err以下抛出,并且节点被挤压:
But when put into a server callback it doesn't work, and throws below err when a request arriving, and node is crush:
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 (_http_common.js:117:23)
推荐答案
结果
var cipher = crypto.createCipher('aes-128-cbc','abcdefghijklmnop')
不应该重复使用。我也将其放入服务器回调中,问题已解决。
should not be reused. I put it into the server callback too and the problem is solved.
这篇关于尝试在Cipher.update中以不受支持的状态添加数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文