Skip to content

Instantly share code, notes, and snippets.

@rfaisal
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rfaisal/9899258 to your computer and use it in GitHub Desktop.
Save rfaisal/9899258 to your computer and use it in GitHub Desktop.
// call: /api/encrypt?app_secret=my_app_secret&access_token=my_access_token
var crypto = require('crypto');
exports.get = function(request, response) {
if(request.query.access_token && request.query.app_secret){
var cipher = crypto.createCipher('aes256', request.query.app_secret);
var encrypted = cipher.update(request.query.access_token, 'utf8', 'hex') + cipher.final('hex');
response.send(statusCodes.OK,{"encrypted_access_token":encrypted});
}
else{
response.send(statusCodes.INTERNAL_SERVER_ERROR,{"error":"both app_secret and access_token is required."});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment