I'm trying to encrypt a basic string on a CFMX v7 app using
the Encrypt function, DES, and Base64 encoded text.
Then I need to pass that to an ASP.Net page where I will
decode it.
It seems that the only way to create a key for the Encrypt
function is by using generateSecretKey("DES"). But if I have to use
the same key on the receiving end how do I force CFMX to use a key
I specify?
Is what I'm trying to accomplish even possible? Is there a
better way to do this?
Do you need to use a pre-specified key, or can you use the
one generated by the generateSecretKey() call? If you have an
existing key you need to use, have you tried passing it into the
encrypt() function using toBase64() to convert it to base 64?
i.e.:
#encrypt("some text to encrypt", toBase64(myDesKey),
"DES")#
I do need to use a pre-specified key. I tried your suggestion
and converted it to Base64 at which point it complained about the
key length being invalid for this encryption. It then suggested
that I use the GenerateSecretKey function.
My code:
encrypted=encrypt("This is a test 100",
toBase64("1A1AA5B64D51677A"),"DES");
It seems as if the DES keys are base64 encoded. not knowing
anything about DES, I don't know if this is standard or not. You
should be able to convert back to binary using a combination of the
toBinary() and toString() CF functions. I think the following will
convert base64 back into normal text: