'Make Nodejs encrypt and decrypt function up to date

I'm trying to make my small function up to date, it generate 2 warnings:

(node:8944) [DEP0106] DeprecationWarning: crypto.createDecipher is deprecated. (node:8944) Warning: Use Cipheriv for counter mode of aes-256-ctr:

Code:

var crypto = require('crypto'),
algorithm = 'aes-256-ctr',
password = 'd6F3Efeq';

function encrypt(text){
  var cipher = crypto.createCipher(algorithm,password)
  var crypted = cipher.update(text,'utf8','hex')
  crypted += cipher.final('hex');
  return crypted;
}
 
function decrypt(text){
  var decipher = crypto.createDecipher(algorithm,password)
  var dec = decipher.update(text,'hex','utf8')
  dec += decipher.final('utf8');
  return dec;
}

This encrypt and decrypt wonderfully, but it generate some errors. I tried the new syntax, and I have a hard time figuring it out. If someone could provide an up to date demo, you're the best. Thank you

PS: I don't want to use createDecipherIv, I only want to use a key if this make sense



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source