我正在使用Heroku上的以下encrypt
函数对一些文本进行加密:
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服务器在美国,而我在英国。时区在这里起什么作用吗?