Skip to content

Instantly share code, notes, and snippets.

@dansitu
Forked from austintaylor/readme.md
Created August 23, 2012 18:46
Show Gist options
  • Save dansitu/3440202 to your computer and use it in GitHub Desktop.
Save dansitu/3440202 to your computer and use it in GitHub Desktop.
An example of creating a UserVoice SSO token using cryptojs
var Crypto = require('cryptojs').Crypto,
UserVoiceAccountKey = "YOUR_ACCOUNT_KEY",
UserVoiceAPIKey = "YOUR_API_KEY";
function createUserVoiceSSOToken(data) {
var key = Crypto.SHA1(UserVoiceAPIKey+UserVoiceAccountKey, {asBytes: true}).slice(0, 16),
json = JSON.stringify(data),
encrypted = Crypto.AES.encrypt(json, key, {mode:new Crypto.mode.CBC(Crypto.pad.pkcs7), iv:'OpenSSL for Ruby', asBytes:true}),
base64 = Crypto.util.bytesToBase64(encrypted),
uriEncoded = encodeURIComponent(base64);
return uriEncoded;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment