节点加密 - 无法反向加密(Node crypto - unable to reverse encryption)
为什么这不打印“你好”?
var cipher = crypto.createCipheriv('rc4', 'secret', ''); crypt = cipher.update('hello', 'binary', 'utf8'); crypt += cipher.final('utf8'); var decipher = crypto.createDecipheriv('rc4','secret', ''); data = decipher.update(crypt, 'binary', 'utf8'); data += decipher.final('utf8'); console.log(data); // prints e/lWhy does this not print "hello"?
var cipher = crypto.createCipheriv('rc4', 'secret', ''); crypt = cipher.update('hello', 'binary', 'utf8'); crypt += cipher.final('utf8'); var decipher = crypto.createDecipheriv('rc4','secret', ''); data = decipher.update(crypt, 'binary', 'utf8'); data += decipher.final('utf8'); console.log(data); // prints e/l最满意答案
utf8不是有效的cipher.final()选项,你想要二进制文件。 尝试这个。
var cipher = crypto.createCipheriv('rc4', 'secret', ''); crypt = cipher.update('hello', 'utf8', 'binary'); crypt += cipher.final('binary'); var decipher = crypto.createDecipheriv('rc4','secret', ''); data = decipher.update(crypt, 'binary', 'utf8'); data += decipher.final('utf8'); console.log(data);utf8 is not a valid cipher.final() option, you want binary. Try this.
var cipher = crypto.createCipheriv('rc4', 'secret', ''); crypt = cipher.update('hello', 'utf8', 'binary'); crypt += cipher.final('binary'); var decipher = crypto.createDecipheriv('rc4','secret', ''); data = decipher.update(crypt, 'binary', 'utf8'); data += decipher.final('utf8'); console.log(data);更多推荐
发布评论