Cryptojs is hosted on Google Code. There is an npm module with source on Github.
Created
July 5, 2012 21:55
-
-
Save austintaylor/3056734 to your computer and use it in GitHub Desktop.
An example of creating a UserVoice SSO token using cryptojs
This file contains 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 characters
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