Skip to content

Instantly share code, notes, and snippets.

@austintaylor
Created July 5, 2012 21:55
Show Gist options
  • Save austintaylor/3056734 to your computer and use it in GitHub Desktop.
Save austintaylor/3056734 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