Con*_*orB 7 amazon-s3 amazon-web-services node.js amazon-dynamodb amazon-elastic-beanstalk
我真的很挣扎如何隐藏我的钥匙.
我需要隐藏的两个密钥是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;
}
};
Run Code Online (Sandbox Code Playgroud)
在Elastic Beanstalk中,我认为存储这样的密钥的首选方法是通过环境变量.您可以使用该命令eb setenv key=value
设置环境变量.关于这方面更多的信息在这里.
要访问您在访问DynamoDB和S3时提到的AWS API,您根本不会使用密钥.为此,您可以将IAM实例配置文件分配给Elastic Beanstalk创建的EC2服务器.这在此处记录.
归档时间: |
|
查看次数: |
1081 次 |
最近记录: |