Skip to content

Instantly share code, notes, and snippets.

@marfarma
Created May 7, 2013 16:56
Show Gist options
  • Save marfarma/5534213 to your computer and use it in GitHub Desktop.
Save marfarma/5534213 to your computer and use it in GitHub Desktop.
var genSignedParamString = function(userID, secret, cmd, params) {
params.userid = userID;
params.command = cmd;
var paramKeys = [];
for(var key in params) {
if(params.hasOwnProperty(key)){
paramKeys.push(key);
};
};
paramKeys.sort(); //you get a cookie if you can tell me why we sort the parameters
var qsParameters = [];
for(var i = 0; i < paramKeys.length; i++) {
key = paramKeys[i];
qsParameters.push(key + '=' + encodeURIComponent(params[key]));
}
var queryString = qsParameters.join('&')
, cryptoAlg = crypto.createHmac('sha1', secret)
, signature = cryptoAlg.update(queryString.toLowerCase()).digest('base64');
return queryString + '&signature=' + encodeURIComponent(signature);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment