【发布时间】:2017-05-30 06:21:22
【问题描述】:
我真的很纠结如何隐藏我的钥匙。
我需要隐藏的两个密钥是 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;
}
};
【问题讨论】:
标签: node.js amazon-web-services amazon-s3 amazon-dynamodb amazon-elastic-beanstalk