I can make an HMAC using the following:
var encrypt = crypto.createHmac(\"SHA256\", secret).update(string).digest(\'base64\');
I am trying
Clean-up of code for a Minimalist View and removal of clutter: note: IIFE runnable in node repl "As Is"
!function(){
const crypto = require("crypto");
// key
var key = crypto.createHash("sha256").digest();
// this is the string we want to encrypt/decrypt
var secret = "ermagherd";
console.log("Initial: %s", secret);
// create a aes256 cipher based on our password
var cipher = crypto.createCipher("aes-256-cbc", key);
// update the cipher with our secret string
cipher.update(secret);
// save the encryption
var encrypted = cipher.final();
console.log("Encrypted: %s", encrypted);
// create a aes267 decipher based on our password
var decipher = crypto.createDecipher("aes-256-cbc", key);
// update the decipher with our encrypted string
decipher.update(encrypted);
console.log("Decrypted: %s", decipher.final()); //default is utf8 encoding final("utf8") not needed for default
}()
/* REPL Output
Initial: ermagherd
Encrypted: T)��l��Ʀ��,�'
Decrypted: ermagherd
true
*/