Created
September 24, 2014 15:32
-
-
Save turret-io/e60ffbd9011a2396f79f to your computer and use it in GitHub Desktop.
Revisions
-
turret-io created this gist
Sep 24, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ var crypto = require('crypto'); var SHARED_SECRET = "sup3rs3cr3t!!"; function signString(string_to_sign, shared_secret) { var hmac = crypto.createHmac('sha512', shared_secret); hmac.write(string_to_sign); hmac.end() return hmac.read(); } var payload = { 'name': 'joe smith', 'category': 'people', 'action': 'transport', 'where': 'pluto', 'timestamp': Math.round(new Date().getTime()/1000) }; var json_payload = JSON.stringify(payload); var signature = signString(json_payload, SHARED_SECRET); var encoded_json = new Buffer(json_payload).toString('base64'); var encoded_signature = new Buffer(signature).toString('base64'); console.log("/?data="+encoded_json+"&signature="+encoded_signature);