Я изучаю NodeJs и пытаюсь реализовать криптографическую библиотеку для шифрования и расшифровки текста,
Я имею в виду следующий пример - https://www.w3schools.com/nodejs/ref_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)
Может ли кто-нибудь помочь реализовать его правильно для шифрования ирасшифровать текст?
Что я делаю не так?