Skip to content

Instantly share code, notes, and snippets.

@nathany
Created April 16, 2010 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathany/368956 to your computer and use it in GitHub Desktop.
Save nathany/368956 to your computer and use it in GitHub Desktop.
<cfscript>
function decodeToken(stoken, crypt_key) {
token_bytes = BinaryDecode(URLDecode(stoken), "base64");
Arrays = CreateObject("java", "java.util.Arrays");
iv = Arrays.copyOf(token_bytes, 16);
crypted = Arrays.copyOfRange(token_bytes, 16, ArrayLen(token_bytes));
decoded_token = DecryptBinary(crypted, crypt_key, "AES/CBC/PKCS5Padding", iv);
return ToString(decoded_token);
}
function derive(secret, prefix) {
keyLen = 16;
key = prefix & secret;
digest = BinaryDecode(Hash(key, "SHA-256"), "hex");
Arrays = CreateObject("java", "java.util.Arrays");
crypt_key = Arrays.copyOf(digest, keyLen);
return ToBase64(crypt_key);
}
</cfscript>
<cfset crypt_key = derive(secret, "ENCRYPTION")>
<cfdump var="#URLDecode(decodeToken(stoken, crypt_key))#">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment