node.js - 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服务器在美国,而我在英国。时区在这里有什么作用吗?
解决方案
推荐阅读
- java - 如何在不下载的情况下在 Azure Devops Agent 中使用特定版本的 Java?
- java - 无法在 android studio 中的选项卡布局的第二个活动中打开 Youtube 嵌入式视频
- python - 在 Graphql 查询中收到不兼容的实例
- mysql - Create a new table in mySQL with specific options
- python - 将句子拆分为其标记作为字符注释 Python
- python - Heroku 错误“找不到该进程类型(网络)”
- python-3.x - Update query in Python using Dictionary key Value pairs
- karate - MSWebDriver fails to run in Karate
- angular - What is the purpose for webcomponents-sd-ce-pf.js
- python - 'DataFrame' 对象没有属性 'date'