在一次成功的encryption和解密之后,Nodejs Crypto解密失败

我在nodejs上有一个奇怪的场景,其中crypto在我加载节点服务器时只对文本进行encryption和解密。 第二次尝试后,它encryption文本罚款,但无法解密的文字,第二次尝试。

这是我的代码:

function Encrypt(mytext) { var cipher = crypto.createCipher('aes-256-cbc','fa97be5d286a67114cf74acf46d179725581d562'); var crypted = cipher.update(mytext,'utf8','hex'); crypted += cipher.final('hex'); } function Decipher(mytext) { var decipher = crypto.createDecipher('aes-256- cbc','fa97be5d286a67114cf74acf46d179725581d562'); var dec = decipher.update(mytext,'hex','utf8'); dec += decipher.final('utf8'); } 

在nodejs服务器加载的时候,这个工作正常,完全encryption和解密数据,第二次使用这个函数在其他地方使用不同的文本或者密钥时,它不能解密文本。 即时puzzeled。

这已经解决后,我已经添加:

删除require.cache [require.resolve('./ templates / prd')];

所需的对象留在caching中,并继续反复encryption。 一旦我清除caching每次我加载模板,它开始正确encryption。