Question

CFencrypt form input

Asked by: bjv211

I have a form for confidential information

<cfform name="travel" action="processtravel.cfm" method="post">
<input name="date" type="hidden">
<input type="hidden" id="time" name="time">
Name of Employee:
   <cfinput name="name" type="text" required="yes">
Contact email address:
   <cfinput name="email" type="text" required="yes" validate="email">
Contact phone number:
   <cfinput name="phone" type="text" required="yes" validate="telephone" mask="(999) 999-9999">
Social Security  
   <cfinput type="password" name="ss" validate="social_security_number" required="yes">
</cfform>

how can i encrypt this data as it passes to the processing page, and then decrypt it to process it.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2006-01-19 at 09:26:07ID21702753
Tags

cfencrypt

,

input

Topic

ColdFusion Application Server

Participating Experts
3
Points
500
Comments
22

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. CFFORM
    Is it possible to call custom JavaScript function on 'onSubmit' event using <CFFORM> But to my knowledge, <CFFORM> not allows the above event. The sitation: I want to do calculations using form fields and store in hidden field and submit if the calculations are ...
  2. CFFORM Natural Break
    Does <CFFORM> and for that matter <FORM> have a natural break or padding after the closing tag? It seems to in my code: -- -- -- -- -- -- -- <table border="1" cellspacing="0" cellpadding="1"> <tr> <td><cfform ac...
  3. CFform and CFMail
    I would like to include CFFORM tags within CFMAIL tags. When the mail recipient receives the email he is asked to complete a small form and submit. These 3 fields populate a table in a database. Is this possible? My code is as follows: <CFMAIL TO="xxx" ...
  4. Cfform validation not working
    I'm quite curious why validation doesnt work for my cfforms ... I have a file called test.cfm and the content: <cfform name="test_validate" action="test.cfm" method="get"> <cfinput name="asdfas" type="text" required=...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: Ike23Posted on 2006-01-19 at 09:44:00ID: 15740763

If you are sending confidential information you should use SSL to encrypt the data.  You will need to have a server with SSL enabled and set up and then all you need to do is add the "https:" to the action page of the form.

<cfform name="travel" action="https://www.yoursite.com/processtravel.cfm" method="post">

 

by: bjv211Posted on 2006-01-19 at 09:45:57ID: 15740790

Why can't I use encrypt thats built into coldfusion?

 

by: javasharpPosted on 2006-01-19 at 09:49:58ID: 15740842

you can use built-in encrypt

 

by: javasharpPosted on 2006-01-19 at 09:52:09ID: 15740870

Check out these securit UDFs
http://cflib.org/library.cfm?ID=7

 

by: Ike23Posted on 2006-01-19 at 09:58:03ID: 15740923

Yes you can do it with encrypt() but if you have SSL it is much easier.  If you don't you will need to use <cfscript> to decrypt() the values and also pass the key to the action page.  I do this with URL variables but haven't tried with form fields.  I'll look for a way with forms but here's the URL example...

http://www.cflib.org/udf.cfm?ID=203

If you are running CF 7 then this is a good technote:
http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=e546373d

 

by: Ike23Posted on 2006-01-19 at 10:06:56ID: 15741043

pinaldave answered a similar question a while back:

http://www.experts-exchange.com/Web/WebDevSoftware/ColdFusion/Q_21654541.html

I think, if you do not want to use post method, javascript and URL param, I would use encrypt and decrypt.

<!--- This example shows the use of Encrypt and Decrypt --->
<h3>Decrypt Example</h3>
<p>This function encrypts/decrypts a string. Enter a string and a key.
<cfif IsDefined("FORM.myString")>
   <cfset string = FORM.myString>
   <cfset key = FORM.myKey>
   <cfset encrypted = encrypt(string, key)>
   <cfset decrypted = decrypt(encrypted, key)>
   <cfoutput>
      <h4><B>The string:</B></h4> #string# <br>
      <h4><B>The key:</B></h4> #key#<br>
      <h4><B>Encrypted:</B></h4> #encrypted#<br>
      <h4><B>Decrypted:</B></h4> #decrypted#<br>
   </cfoutput>
</cfif>
<form action = "encrypt.cfm">
<p>Input your key:
<p><input type = "Text" name = "myKey" value = "foobar">
<p>Enter string to encrypt:
<p><textArea name = "myString" cols = "40" rows = "5" WRAP = "VIRTUAL">
This string will be encrypted (try typing some more)</textArea>
<input type = "Submit" value = "Encrypt my String">
</form>

 

by: bjv211Posted on 2006-01-19 at 10:23:40ID: 15741218

but does this encrypt through the pass or after?

 

by: Ike23Posted on 2006-01-19 at 10:35:14ID: 15741322

The URL method encrypts before the pass but I haven't used the form method.  I'm not sure if you would need to use the method="GET" in your form but that would pass the values as URL values instead of form values.

Are you trying to encrypt every form field or do you just need to encrypt the password?  If you are going to use a Social Security Number as a password it would be suggested to use SSL.  If you can't then make sure you use a really long key to encrypt the value before you send it.  I'll look around but I'm pretty sure you would need to use <cfscript> if order to change a form field before it is sent but I haven't done this before.

 

by: bjv211Posted on 2006-01-19 at 10:49:09ID: 15741467

i just want to ensure that the SS is encrypted when its passed. I dont have to use it as password form field. I am looking into SSL for testing now and will repost different question there. for this thread i want to focus on can i encrypt form values before their passed?

 

by: Ike23Posted on 2006-01-19 at 11:07:32ID: 15741633

The only way it might work is if you create a function in cfscript and call it when the form is submitted that would encrypt the ss number form field before it was sent.  

Something like:

<cfscript>

     function encryptSS(formvalue, key){

      // encode the ss number
      var newSS = cfusion_encrypt(formvalue, key);
       
            
      return newSS;
     }
</cfscript>

<input type="password" name="ss" id="ss" validate="social_security_number" required="yes" >

<cfset yourKey = "somecrazykeywithnumbersandletters">

<input type = "Submit" value = "Submit" onClick="document.ss.value=encryptSS(document.ss.value,#yourKey#);">

That's the idea but you will need the same key to decrypt the number on the action page.  Don't send the key to the action page or someone could get your key and then they could decrypt the value themselves.  

Hope this helps to point you in the right direction!

 

by: bjv211Posted on 2006-01-19 at 13:54:33ID: 15743434

ok this is what i have for testing purposes

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<cfscript>
     function encryptSS(formvalue, key){
     // encode the ss number
     var newSS = cfusion_encrypt(formvalue, key);
     return newSS;
     }
</cfscript>
<body>
<cfform method="post" action="encproc.cfm">
<cfinput type="password" name="ss" id="ss" validate="social_security_number" required="yes" >
<cfset yourKey = "somecrazykeywithnumbersandletters">
<input type = "Submit" value = "Submit" onClick="document.ss.value=encryptSS(document.ss.value,#yourKey#);">
</cfform>
</body>
</html>

-----encproc.cfm-------

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<cfset yourKey = "somecrazykeywithnumbersandletters">
<cfset decryptedSS = decrypt(form.ss,yourKey)>
<body>
<cfoutput>Before Decrypt: #form.ss#<br>After Decrypted: #decryptedSS#</cfoutput>
</body>
</html>

 

by: bjv211Posted on 2006-01-19 at 13:55:23ID: 15743443

i'm gettin the following error

There has been an error while trying to encrypt or decrypt your input string: The input and output encodings are not same..  
 
 
The error occurred in C:\Inetpub\wwwroot\forms\encproc.cfm: line 8
 
6 : </head>
7 : <cfset yourKey = "somecrazykeywithnumbersandletters">
8 : <cfset decryptedSS = decrypt(form.ss,yourKey)>
9 : <body>
10 : <cfoutput>Before Decrypt: #form.ss#<br>After Decrypted: #decryptedSS#</cfoutput>

 

by: Ike23Posted on 2006-01-19 at 14:22:46ID: 15743704

It doesn't seem to be encrypting the value in the first place.  The cfscript I wrote was just an example of the logic but you will probably need to debug it and maybe do another post to see if any cfscript masters can get it to work.  I created a page for you that will illustrate that the value being passed hasn't been encrypted yet:

<cfif isdefined("form.ss")>

<cfset yourKey = "abc123blabla">
<!--- <cfoutput><cfset decryptedSS = "#decrypt(form.ss,yourKey)#"></cfoutput> --->
<cfset decryptedSS = "not encrypted">
<cfoutput>Before Decrypt: #form.ss#<br>After Decrypted: #decryptedSS#</cfoutput>


<cfelse>

<cfscript>
     function encryptSS(formvalue, key){
     // encode the ss number
     var newSS = cfusion_encrypt(formvalue, key);
     return newSS;
     }
</cfscript>

<cfform method="post" action="encproc.cfm">
<cfinput type="text" name="ss" id="ss" validate="social_security_number" required="yes" >
<cfset yourKey = "abc123blabla">
<input type = "Submit" value = "Submit" onClick="document.ss.value=encryptSS(document.ss.value,#yourKey#);">
</cfform>

</cfif>

This will let you use the same page for the form and the action page.  The idea behind this is to script a function that will take the form.ss value and encrypt it before it is sent by the form.  Once you get the value to be passed as encrypted then the code I gave will work for decrypting it.

 

by: bjv211Posted on 2006-01-19 at 14:24:41ID: 15743737

i gotcha now
i'll work on it

 

by: Ike23Posted on 2006-01-19 at 14:25:08ID: 15743741

Actually the form will need a name and you will need to call that in the script.

<cfform method="post" name="ssform" action="encproc.cfm">
<cfinput type="text" name="ss" id="ss" validate="social_security_number" required="yes" >
<cfset yourKey = "abc123blabla">
<input type = "Submit" value = "Submit" onClick="document.form.ssform.ss.value=encryptSS(document.form.ssform.ss.value,#yourKey#);">
</cfform>

I'm had problems trying to do javascript validation with a cfform so i usually just use a plain <form> tag instead.  

 

by: Ike23Posted on 2006-01-19 at 14:36:48ID: 15743837

I'm pretty sure you can't use the DOM inside of a <cfscript> block now that I think about it.  So it doesn't look good unless you find a function inside javascript to encrypt() your value before it is sent.  

If you have any chance of installing or using an SSL certificate that is by far the best way to do this.  With information as sensitive as a social security number I wouldn't go with anything less.

 

by: substandPosted on 2006-01-22 at 14:20:02ID: 15762280

Even if you write or find a javascript function to encrypt the value before it is sent (and presumably a matching cf function that will decrypt it at the server), it is still pointless.  People can view the source to find the javascript that encrypts it and work backwards from there.

Use SSL.

 

by: bjv211Posted on 2006-01-23 at 06:45:07ID: 15766737

Alright, got an SSL up and running. thanks for the advice, please tell me a good use for CFENCRYPT if you dont mind.

 

by: substandPosted on 2006-01-23 at 09:05:45ID: 15768110

One use I've found for it is if you have a login that is based on a cookie being an easy to guess value... for instance, if you have

<cfparam cookie.userid=0>
<cfif cookie.userid gt 0> <!--- ie, you've logged them in already --->
   show them the goods!
</cfif>

then someone cannot see the 0 in their cookies and just think "if i change this to 1, i can be logged in" (and then they could see someone else's information too)

another use I've had is when I need to pass customer data (or a user ID) through the URL between different sites on the same server... if they were on only one site, I could just read the session or cookie and do all db lookups there... but if you have to pass it to another site (or if you are putting them in forms or urls for some reason and then doing db lookups) people can see that "userID=503" or whatever and change the number to see someone else's info.  Encrypting the value helps there too.

You might also encrypt sensative data that will be stored in your database as well.  This way, if someone manages to find a way to your data and not your code, you aren't as worried.

 

by: Ike23Posted on 2006-01-24 at 09:28:38ID: 15777737

I find it useful when I want to encrypt values in my URL also.  Here's the link to the UDF that I posted earlier.  If you are passing an integer in your URL and using it in a query it's also good to use <cfqueryparam> to prevent injection attacks.

http://www.cflib.org/udf.cfm?ID=203

Select * from table
Where yourID = <cfqueryparam sqltype="integer" value="#url.ID#">

Ike23

 

by: Ike23Posted on 2006-01-24 at 11:11:54ID: 15778798

Here's an article that was just posted on the ColdFusion Developer's Journal which explains some ways to use CF's built in encryption.  Hopefully in the next release they will have the public and private key option available.

http://coldfusion.sys-con.com/read/172571.htm

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...