I really fight for how I should hide my keys.
The two keys I need to hide are secrets.crypto and secrets.jwt ... I plan to host my application on AWS using Elastic Beanstalk.
Also, I'm not sure where I would put my keys to access things like my Dynamodb and my S3 bucket.
exports.generateToken = (type, user) => { if (!_.isString(type)) { return undefined; } try { //Turn the json object of the current user 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
source share