Welcome!

ColdFusion Authors: Maureen O'Gara, Hovhannes Avoyan, Yakov Fain, Pat Romanski, Liz McMillan

Related Topics: ColdFusion

ColdFusion: Article

Public-Key Encryption

Making strong encryption nearly painless

To allow your users to provide their own public key to your public keyring, the importKey() method is particularly useful. By passing the importKey() method the public key you are able to store it for use on your public key ring. If the key is invalid, an error data stream is returned:

   badKey = gpg.importKey("not a key");
<cfoutput><pre>#badKey#</pre></cfoutput>

which generates the following message:

gpg: no valid OpenPGP data found.
gpg: Total number processed: 0

If you would like to maintain your user's keys on the server, you can generate key pairs by invoking the newKey() method. This method takes several arguments: a real name, comment (helps differentiate people of the same name), e-mail address, expiration date (see comments for usage), and a passphrase. Again, since this method passes sensitive data, as do most methods in the GnuPG object, it is important to secure the transmission of that data via SSL. The newKey() method does take a few seconds to complete, as GnuPG implements complex mathematical algorithms to generate your public and secret keys.

Signing data is another important aspect of this wrapper. Signing allows others to verify that a data stream was not tampered with, be it a Web page, source file, image, or any other type of data stream. As with encrypt and decrypt, you utilize the sign/verify methods in the CFC.

   signed = gpg.sign("Text to sign.", "passphrase");
   verify = gpg.verify(signed);

The output from the verify variable will notify you if the signature matches the key ring. One potential use of this is to sign download files that you might host on your site. The examples included with this article show you how to create a file upload system that automatically signs files that you might have on your Web site for download. Also included, is a simple e-mail encryption example that allows you to quickly integrate encrypted e-mail into your existing ColdFusion e-mail application. Examples using this CFC and Java wrapper can be downloaded from www.sys-con.com/coldfusion/sourcec.cfm.

Conclusion
The CFC and Java wrappers for Gnu Privacy Guard make it nearly painless to integrate strong encryption into your programming projects. However, if you do not take the proper steps in encrypting transmission, or remain vigilant in your security implementation using strong key encryption methods as provided here, your work will be for naught. GnuPG does a very good job at securing data, as long as the passphrase is kept secret. Developing an encryption system that does not require user intervention will require the storage of passphrases in a database or other persistence mechanism. It is essential that this security issue be addressed during the design phase of your project, and that steps be taken to properly obfuscate the passphrases.

References

  • van Oorschot, P., and Wiener, M. 1994. "Parallel Collision Search with Applications to Hash Functions and Discrete Logarithms." 2nd ACM Conference on Computer and Communications Security. ACM Press.
  • The Diceware Passphrase FAQ: http://world.std.com/~reinhold/dicewarefaq.html#howlong
  • More Stories By Wayne Graham

    Wayne Graham is a systems administrator at the College of William and Mary's Earl Gregg Swem Library. Wayne is also the co-manager of the Williamsburg Macromedia User's Group and has been developing with ASP, Java, and ColdFusion since 2001.

    Comments (10) View Comments

    Share your thoughts on this story.

    Add your comment
    You must be signed in to add a comment. Sign-in | Register

    In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


    Most Recent Comments
    Thomas Gorgolione 07/23/08 05:05:27 PM EDT

    You have to compile the code manually from the zip file (see post #5). I did that already, so if you want you can just download it here:

    www.tgorg.com/etc/GnuPG.jar

    Jeff 01/31/08 08:07:47 AM EST

    Does anyone have the GnuPG.jar file? I found the CF component but that still needs the GnuPG.jar file to operate and the link in the article to get GnuPG.jar does not work.

    Shaun 09/04/07 02:21:25 PM EDT

    Found this:
    http://res.sys-con.com/story/46359/source.html

    William Broadhead 07/21/05 03:00:51 PM EDT

    Good story. Very informative. One thing I would note is that in cf using the encrypt/decrypt: You don't have to, and shouldn't include the actual key in your code, NOR in your Database... A tecnnique I use is to store the key in a text file on the server in a directory that is accessible to coldfusion but NOT part of the http accessible directory. Using cffile you can read and load the information in the file to memory as an application key to use for hashing passwords while never having the key in your code nor in your database. Although obviously, as the article points out, security can never be completely infallible, this can reduce the capacity of your data to be compromised if you did somehow lose a copy of your database or page code, you would need also need to lose the file for someone to put it all together...

    Mark 07/14/05 01:53:05 PM EDT

    Great article, very well written.

    Brad 03/28/05 10:13:32 AM EST

    Great Article, convinced my peers to use this instead of upgrading to CF7Mx.

    As for the gentleman looking for the source, click the Source Code link located under Related Sites. Scroll down... you're welcome.

    Nguyen Tran 03/21/05 10:50:00 AM EST

    Where to download the file? GnuPG.jar

    The link you provided as:
    www.sys-con.com/coldfusion/sourcec.cfm
    Point to the page at:
    http://sys-con.com/magazine/archives.cfm?id=5

    On this page, there is no link to download the file GnuPG.jar

    Please give us the link to download the file GnuPG.jar

    Thank you

    Tom 02/08/05 06:05:04 AM EST

    hello,

    i´ve the same problem: where is gnupg.jar?
    regards, tom

    Shane 12/16/04 11:14:17 AM EST

    nevermind.... I found it.

    Shane 12/16/04 11:09:21 AM EST

    Great article. I've been looking forward to trying this out but haven't been able to find the gnupg.jar file. Am I overlooking it somewhere? Please advise.

    Thanks.