-
-
Save ivanionut/10178ef6c73f7bfcd701 to your computer and use it in GitHub Desktop.
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 characters
<cfscript> | |
/* ColdFusion 11 dropped the undocumented cfusion_encrypt & decrypt functions while Railo 4.2 still officially supports it. | |
This script will reestablish the built-in function. You can also use fusion_encrypt/decrypt (without the "c"). | |
Based on 2005 blog post: http://www.barneyb.com/barneyblog/2005/10/28/cfusion_encryptcfusion_decrypt-udfs/ */ | |
function fusion_binaryXOR(n1, n2){ | |
n1 = formatBaseN(n1, 2); | |
n2 = formatBaseN(n2, 2); | |
return inputBaseN(replace(n1 + n2, 2, 0, "all"), 2); | |
} | |
function fusion_encrypt(string, key){ | |
var i = 0; | |
var result = []; | |
key = repeatString(key, ceiling(len(string) / len(key))); | |
for (i=1;i LTE len(string);i=i+1) { | |
arrayAppend(result, rJustify(formatBaseN(fusion_binaryXOR(asc(mid(string, i, 1)), asc(mid(key, i, 1))), 16), 2)); | |
} | |
return ucase(replace(arrayToList(result,""), " ", "0", "all")); | |
} | |
function fusion_decrypt(string, key){ | |
var i = 0; | |
var result = []; | |
key = repeatString(key, ceiling(len(string) / 2 / len(key))); | |
for (i=2;i LTE len(string);i=i+2) { | |
arrayAppend(result, chr(fusion_binaryXOR(inputBaseN(mid(string, i - 1, 2), 16), asc(mid(key, i / 2, 1))))); | |
} | |
return arraytoList(result,""); | |
} | |
if (NOT StructKeyExists(Server, "Railo") AND VAL(ListFirst(Server.ColdFusion.ProductVersion)) GTE 11){ | |
cfusion_encrypt = fusion_encrypt; | |
cfusion_decrypt = fusion_decrypt; | |
} | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment