问题描述
所以这个想法很简单,但是我不确定我是否做对了。 在我的应用程序中,我需要为某些数据库连接使用用户名/密码。 信息存储在我的.bashrc文件中,并导出env vars。 我不想以明文形式存储它们,所以我想以加密形式存储它们。 在运行时,我读取了env变量,对其进行解密并使用它们。
我目前拥有的是一个进行加密的node.js应用程序, 代码段:
const crypto = require('crypto');
const emailPassword = CLEAR_TEXT_PASSWORD;
const algorithm = 'aes-192-cbc';
const password = 'p3241';
const key = crypto.scryptSync(password,'salt',24);
const iv = Buffer.alloc(16,0);
const cipher = crypto.createCipheriv(algorithm,key,iv);
let encrypted = cipher.update(emailPassword,'utf8','hex');
encrypted += cipher.final('hex');
console.log(encrypted);
以上结果成为我的env变量。
现在在我的消费者应用程序中,要使用env变量,我在使用之前有一个与解密相反的例程。
看起来像
export const decipher = (input: string) : string => {
const algorithm = 'aes-192-cbc';
const password = 'p3241';
const key = crypto.scryptSync(password,24);
const iv = Buffer.alloc(16,0);
const decipher = crypto.createDecipheriv(algorithm,iv);
let decrypted = decipher.update(input,'hex','utf8');
decrypted += decipher.final('utf8');
console.log(decrypted);
return decrypted;
}
但是我所没有的所有用于加密/解密的参数都以明文形式显示在服务器上的代码中。
有更好的方法吗?还是我过于偏执?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)