Using toBase64 and urlencrypt renders a string that should always be db-safe to store. 
 No quote marks and such.

Below is a sample template I worked up to play around with various (documented) 
encryption options.  Run it (name the file anything you like) and it'll encrypt stuff 
in various formats and decrypt it from those formats with results onscreen.  Its 
pretty handy.

FYI I personally don't like using cfusion_encrypt() as its undocumented.  Works 
better, but no telling for how long it'll continue to exist.

-------------------------------------------
 Matt Robertson,     [EMAIL PROTECTED]
 MSB Designs, Inc. http://mysecretbase.com
-------------------------------------------
<CFSET variables.mystring=CreateUUID()>
<CFSET variables.tempstring=CreateUUID()>
<CODE>
<HTML><HEAD><TITLE>Encrypt Example</TITLE></HEAD><BODY>
<H3>Encrypt Example</H3>
<P>This function allows for the encryption and decryption of a 
string. Try it out by entering your own string and a key of your 
own choosing and seeing the results.
<CFIF isdefined ("url.Action")>
        <CFSET string = FORM.myString>
        <CFSET key = FORM.myKey>
        <CFSET encrypted = encrypt(string, key)>
        <CFSET urlencrypted = URLEncodedFormat(encrypt(string, key))>
        <CFSET base64encrypted = ToBase64(encrypt(string, key))>
        <CFSET UrlBase64encrypted = URLEncodedFormat(base64encrypted)>
        <CFSET decrypted = decrypt(encrypted, key)>
        <CFSET urldecrypted = URLDecode(urlencrypted)>
        <CFSET urldecrypted = decrypt(urldecrypted, key)>
        <CFSET dbsafedecrypted = decrypt(tostring(tobinary(base64encrypted)),key)>
        <CFSET urldbsafedecrypted = URLDecode(urlbase64encrypted)>
        <CFSET urldbsafedecrypted = 
decrypt(tostring(tobinary(urldbsafedecrypted)),key)>
        <CFOUTPUT>
        <UL>
        <LI><B>The string:</B> #string#</LI>
        <LI><B>The key:</B> #key#</LI>
        <LI><B>Encrypted in normal format:</B> #encrypted#</LI>
        <LI><B>Encrypted in URLEncodedFormat:</B> #urlencrypted#</LI>
        <LI><B>Encrypted in Base64 format:</B> #base64encrypted#</LI>
        <LI><B>Encrypted in UrlEncoded Base64 format:</B> #urlbase64encrypted#</LI>
        <HR WIDTH="80%">
        <LI><B>Decrypted from normal format:</B> #decrypted#</LI>
        <LI><B>Decrypted from UrlEncoded format:</B> #urldecrypted#</LI>
        <LI><B>Decrypted from Base64 format:</B> #dbsafedecrypted#</LI>
        <LI><B>Decrypted from UrlEncoded Base64 format:</B> #urldbsafedecrypted#</LI>
        </UL>
        <FORM ACTION="encdec.cfm?Action=1&ssn=#urlbase64encrypted#" METHOD="post">
        Input your key:<BR>
        <INPUT TYPE="Text" NAME="myKey" VALUE="#form.myKey#" SIZE="40">
        <P>Input your string to be encrypted:<BR>
        <textArea NAME="myString" cols="40" rows="5" 
WRAP="VIRTUAL">#form.myString#</textArea>  
        <P>Here's an html link with the base64 urlencoded string:<BR>
        <textArea NAME="myLink" cols="40" rows="5" WRAP="VIRTUAL">&lt;A 
HREF="http://mydomain/mypage.cfm?ssn=#urlbase64encrypted#"&gt;Click 
Here&lt;/A&gt;</textArea><BR>
        Here's another UUID: #variables.TempString#
        </CFOUTPUT>
<CFELSE>
        <cfoutput><FORM ACTION="#cgi.script_name#?Action=1" METHOD="post"></cfoutput>
        Input your key:<BR>
        <INPUT TYPE="Text" NAME="myKey" SIZE="40">
        <P>Input your string to be encrypted (this is a UUID):<BR>
        <textArea NAME="myString" cols="40" rows="5" 
WRAP="VIRTUAL"><CFOUTPUT>#variables.MyString#</CFOUTPUT></textArea><BR>
        Here's another UUID: <CFOUTPUT>#variables.TempString#</CFOUTPUT>
</CFIF>
<BR><INPUT TYPE="Submit" VALUE="Encrypt my String">
</FORM></CODE></BODY></HTML>

 
             
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: 
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq

This list and all House of Fusion resources hosted by CFHosting.com. The place for 
dependable ColdFusion Hosting.
http://www.cfhosting.com

                                Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
                                

Reply via email to