-
-
Save JamoCA/3ff817138c64bf9a49d8 to your computer and use it in GitHub Desktop.
<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> |
Hi, thank you for this functions ! but ...
on CF9 + windows2008 machine the encodeds strings are the same only if the encriptying key have not characters like "é" "à" etc.
If the encriptying key have unicode character the encrypted strings are identical only if the number of characters is less then 16
Any idea ?
thanks
I test with this code :
`
/* 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 xfusion_binaryXOR(n1, n2){
n1 = formatBaseN(n1, 2);
n2 = formatBaseN(n2, 2);
return inputBaseN(replace(n1 + n2, 2, 0, "all"), 2);
}
function xfusion_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(xfusion_binaryXOR(asc(mid(string, i, 1)), asc(mid(key, i, 1))), 16), 2));
}
return ucase(replace(arrayToList(result,""), " ", "0", "all"));
}
function xfusion_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(xfusion_binaryXOR(inputBaseN(mid(string, i - 1, 2), 16), asc(mid(key, i / 2, 1)))));
}
return arraytoList(result,"");
}
cfset key = "encryptage du Decofinder" />
cfset key = "voilà et écoute" />
#xfusion_encrypt(theString,key) is cfusion_encrypt(theString,key)#
#cfusion_encrypt(theString,key)#
#xfusion_encrypt(theString,key)#
#cfusion_decrypt(cfusion_encrypt(theString,key),key)#
#xfusion_decrypt(xfusion_encrypt(theString,key),key)#
`
Thank you! Migrating from ColdFusion 8 to Adobe CF 2016 or Lucee and this was a bit of a sticking point.