我正在学习NodeJs,我试图实现密码库来加密和删除文本,
我指的是以下示例- crypto.asp
要加密的代码如下-
var crypto = require('crypto');
var mykey = crypto.createCipher('aes-128-cbc', 'mypassword');
var mystr = mykey.update('abc', 'utf8', 'hex')
mystr += mykey.update.final('hex');
console.log(mystr); 要解密的代码如下-
var crypto = require('crypto');
var mykey = crypto.createDecipher('aes-128-cbc', 'mypassword');
var mystr = mykey.update('34feb914c099df25794bf9ccb85bea72', 'hex', 'utf8')
mystr += mykey.update.final('utf8');
console.log(mystr);代码样本似乎适用于它们的环境,
但是当我试图在我的机器上运行相同的代码时,我得到了以下错误-
mystr += mykey.update.final('hex');
^
TypeError: mykey.update.final is not a function
at Object.<anonymous> (/home/user/office/pocs/node-apps/sample-apps/Apps/crypto.js:5:23)
at Module._compile (internal/modules/cjs/loader.js:734:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:745:10)
at Module.load (internal/modules/cjs/loader.js:626:32)
at tryModuleLoad (internal/modules/cjs/loader.js:566:12)
at Function.Module._load (internal/modules/cjs/loader.js:558:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:797:12)
at executeUserCode (internal/bootstrap/node.js:526:15)
at startMainThreadExecution (internal/bootstrap/node.js:439:3)可以帮助正确地实现它来加密和删除文本吗?
我做错什么了?
发布于 2019-02-10 12:16:54
https://stackoverflow.com/questions/54616146
复制相似问题