首页 > 解决方案 > Heroku 生产服务器加密和本地解密失败

问题描述

encrypt在 Heroku 上使用以下函数加密一些文本:

const crypto = require('crypto');

// function to encrypt data ....
function encrypt(KEY, text){
  const cipher = crypto.createCipher('aes192', KEY);
  var encrypted = cipher.update(text,'utf8', 'hex');
  encrypted += cipher.final('hex');
  return encrypted;
}

// function to decryt data..............
function decrypt(KEY, text){ 
    const decipher = crypto.createDecipher('aes192', KEY) 
    var decrypted = decipher.update(text,'hex','utf8') 
    decrypted += decipher.final('utf8'); 
    return decrypted; 
 }

然后它将我加密的文本保存到 MongoDb 服务器。我读取了加密的值并尝试在本地机器上对其进行解密,但得到一个digital envelope routines:EVP_DecryptFinal_ex:bad decrypt. 我花了很多时间试图找出问题所在。

在 Heroku 和本地我都使用相同的密钥。如果我在本地尝试此代码(即在本地加密和解密),那么一切都按预期工作。

你知道可能出了什么问题吗?

我注意到heroku服务器在美国,而我在英国。时区在这里有什么作用吗?

标签: node.jsherokuencryption

解决方案


推荐阅读