我真的很挣扎,应该如何隐藏我的钥匙。我应该在哪里存储我的Node.js应用程序的密钥?
我需要隐藏的两个密钥是secrets.crypto和secrets.jwt ...我计划使用Elastic Beanstalk在AWS上托管我的应用程序。
此外,我不知道在哪里放置我的密钥以访问Dynamodb和S3存储桶等内容。
exports.generateToken = (type, user) => {
if (!_.isString(type)) {
return undefined;
}
try {
//Turn the json object of the current user's id and the type of token into a string
var stringData = JSON.stringify({
_id: user._id,
type: type
});
//Take the json string and encrypt it with a secret then turn it back into a string
var encryptedData = cryptojs.AES.encrypt(stringData, secrets.crypto).toString();
//Take the encryptedData and turn it into a token with a secret
var token = jwt.sign({
token: encryptedData
}, secrets.jwt);
return token;
} catch(e) {
return undefined;
}
};
这也是一种“安全方式” – ConnorB
eb setenv调用将通过SSL连接将密钥名称和值发送到AWS API,因此它是设置值的安全方式。我相信您也可以通过AWS Web控制台执行相同的操作。只要您限制访问您的AWS账户,它就是“安全”的。如果您希望获得更多有关这些值的安全性,可以使用AWS Key Management Service(KMS)进行研究。您将不得不在构建应用程序时使用该服务,因为它与Elastic Beanstalk没有紧密集成。 –