如何避免在纯文件中的密钥?

我正在使用Node.js和Mysql,我想encryption我的数据库上的数据。 我想知道如何避免将简单的密钥存储在一个容易find的文件中,做AES_ENCRYPT(text, key)对我来说没有意义,因为我传递了一个普通的密钥,可以在服务器上读取没有问题的普通密钥。

有什么build议? 不对称encryption?

谢谢

您可以让用户在启动时使用readline模块提供密钥:

你的应用:

 module.exports = function(key) { var app = // ... } 

你的开始脚本:

 var readline = require('readline') , interface = readline.createInterface(process.stdin, process.stdout, null); interface.question("Please supply a key", function(key) { // load your app, supplying the key require("./app")(key); interface.close(); process.stdin.destroy(); }); 

在将数据发送到MySQL服务器之前,我会encryption任何数据,以防止日志中出现未encryption的数据。 以下信息将讨论Node.jsencryption模块,它应该根据需要进行操作。 这样,所有离开你的服务器都是encryption的string,如果没有密钥,使用起来就会less得多。

Node.jsencryption模块文档: http : //nodejs.org/docs/latest/api/crypto.html