1

Is there an encryption algorithm in ColdFusion that doesn't use any special characters (only alphanumeric)? I have some data that I am passing to a user as a pseudo password which includes their username and the site that they are assigned to. I need to encrypt the string with an encryption algorithm built into ColdFusion 8 Enterprise edition and it cannot have any special characters in the final string. Is this possible and if so what algorithm will do this?

<cfset loc.token = encrypt(loc.token,Application.secretKey,'Blowfish','Base64') />
5
  • Just encode the result in base-64!
    – Kerrek SB
    Jul 7, 2011 at 20:14
  • It already is in base64 :) ie That is what the fourth parameter does ie sets the encoding of the output string
    – Leigh
    Jul 7, 2011 at 20:47
  • @Leigh: D'oh, indeed -- I was careless and just thought "ASCII printable", but he really wants only alphanumerics. Sorry!
    – Kerrek SB
    Jul 7, 2011 at 20:51
  • @Kerrek SB - No worries. I was not thinking hex at first either.
    – Leigh
    Jul 7, 2011 at 20:55
  • If you want something with more characters than hex, there's also Douglas Crockford's base32 encoding.
    – hammar
    Jul 12, 2011 at 17:20

3 Answers 3

4

Just use binhex. Encode each byte as a hexadecimal number, ranging from 00 to FF. Base 64, however, includes several nonalphanumeric characters, such as + / = .

6
  • Right - binhex is a 4-bit, base-64 is 6-bit encoding. Whatever floats your boat. For truely alphanumeric output binhex is indeed better.
    – Kerrek SB
    Jul 7, 2011 at 20:19
  • Well, we can come up with a compromise: Base32, which is a 5-bit encoding, though this is presumably less well known than binhex or Base 64
    – Peter O.
    Jul 7, 2011 at 20:26
  • 1
    Nice. Though it still seems to include = for padding :-( Or do you mean base32hex? How about Crockford's Base32, which disallows accidental obscenity? (Presumably invented on expertsexchange.com.)
    – Kerrek SB
    Jul 7, 2011 at 20:30
  • 1
    @Kerrek SB - +1. Haha. I did not know about the excluded letters. @Peter O - Good idea. In CF it is just a matter of changing the encoding parameter to "hex" ie encrypt(text, key, algorithm, encoding)
    – Leigh
    Jul 7, 2011 at 20:40
  • If I changed the Base64 argument of the function to "hex" it worked perfectly with no special characters.
    – Dave Long
    Jul 7, 2011 at 20:46
2

This should work for you,

#encrypt('text_im_encrypting', ToBase64(BinaryDecode('my_encrypt_key',"Hex")), 'AES', 'Hex');#

replace the *text_im_encrypting* and *my_encrypt_key* values obviously... =)

0
-1

There are two undocumented functions, cfusion_encrypt(string, key) and cfusion_decrypt(string, key), that encrypt/decrypt based on hexadecimal strings. So essentially, since the resulting string is completely hex, it contains no special characters:

<cfscript>
    writeoutput(cfusion_encrypt("stackoverflow", "rocks")); // outputs 011B0208181D190619151E0014
    writeoutput(cfusion_decrypt("011B0208181D190619151E0014", "rocks")); // outputs stackoverflow
</cfscript>
3
  • That is not the same. It does not use the "Blowfish" algorithm.
    – Leigh
    Jul 13, 2011 at 16:40
  • @Leigh: Did you read the question? He didn't ask for a blowfish algorithm - he asked for an algorithm that didn't return any special characters.
    – Phydiux
    Jul 13, 2011 at 16:56
  • What I meant was, I think you misunderstood the question. He asked about an algorithm for the encrypt function. So cfusion_encrypt probably is not what he is looking for (it also does not provide real/strong encryption). All that is needed is to use encrypt(text, key, algorithm, "hex") and no more special characters.
    – Leigh
    Jul 13, 2011 at 18:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.