| By Wayne Graham | Article Rating: |
|
| September 15, 2004 12:00 AM EDT | Reads: |
42,216 |
Type your name as you would like it to appear and hit the enter key. Next, type your e-mail address (and enter). The last field is an optional comment field, which allows you to add a comment to the key entry to further identify you (bet there are a lot of John Smiths out there) without necessarily knowing an e-mail address. You are then prompted to review your entry and given the opportunity to change any of the fields. If everything is okay, type the letter "O" and hit the enter key.
Finally, your Diceware passphrase needs to be typed and verified. After all this data has been entered, GnuPG generates two database files (pubring.gpg and secring.gpg) to hold your keys. GnuPG will display the keys you have just generated, along with the generated key's fingerprint:
public and secret key created and signed.
key marked as ultimately trusted.
pub 1024D/D0D63B4A 2004-08-09 cfTest (ColdFusion test account)
<test@nowhere.com>
Key fingerprint = 7894 04AD B584 2DBD AE71 3101 6FEE 8A8F D0D6 3B4A
sub 1024g/E614ABE6 2004-08-09
You do not need to write any of this information down; as long as you know your passphrase you will be able to use this key for encryption/decryption and hashing functions. With all of this done, it's time to start hooking GnuPG up to ColdFusion!
Java Wrapper
There are several options for getting GnuPG to interact with ColdFusion. A common approach to extending ColdFusion with external objects is to write COM, CORBA, or Java wrappers; in the case of GnuPG, <cfexecute> is also an option. (However, <cfexecute> may not work as desired when returning large amounts of data results to the browser using the variable attribute.) My background is in Java, so I implemented the wrapper for GnuPG in Java.
The Java implementation is relatively straightforward, consisting of two objects: GnuPG and ProcessStreamReader. The ProcessStreamReader object's purpose is to read the standard output generated by the GnuPG binaries. GnuPG.java is also very straightforward, with most of the methods simply constructing the commands to pass to the gpg executable. The main workhorse of the object is the private method runGnuPG, used for actually processing input/output.
Download GnuPG.jar from www.sys-con/coldfusion/sourcec.cfm and place the file in your classpath folder (WEB-INF/lib) or create a classpath variable in the ColdFusion Administrator. You will need to restart your ColdFusion server before you can use the classes in the GnuPG package.
CFC
The logic for executing GnuPG commands resides in the Java wrapper, so the methods contained within the cfGnuPG CFC (see Listing 1) are extremely short. In fact, after creating the Java object, each of the methods in the CFC simply call their Java counterpart in the Java archive, as shown by the following example:
<cffunction name="gpgEncrypt" access="public" displayname="Encrypt"
hint="Encrypts data streams using GnuPG." output="No">
<cfargument name="str" required="Yes" type="string" hint="Data stream to
encrypt.">
<cfargument name="keyID" required="Yes" type="string" hint="User key to
encrypt to.">
<cfscript>
return gpg.encrypt(arguments.str, arguments.keyID);
</cfscript>
</cffunction>
Usage
You're now ready to take a test drive of the GnuPG system in ColdFusion! All that is required to begin using the component on the server is knowing the absolute path to the GnuPG binaries. On Windows systems you can initialize the component like this:
<cfscript>
gpg = createObject("component", "cfGnuPG");
gpg.init("c:\gnupg\gpg.exe");
</cfscript>
After the GnuPG wrapper has been initialized, you have access to all of the methods contained in the component object. Invoking each of the methods then becomes almost effortless. To invoke the listKeys() method to display all the keys on your public key ring, you would simply create a variable that accesses the object and its method within the <cfscript> block:
keys = gpg.listKeys();
<cfoutput> can then be used to return the results of GnuPG to the browser. Encrypting a message is just as easy. Simply invoke the gpgEncrypt() method with the text you want to encrypt and the key you would like to encrypt the message to.
encrypted = gpg.gpgEncrypt("message", "recipient's key");
Decrypting a message is also simple (if you know the passphrase). Just as when using gpgEncrypt() to encrypt a message, gpgDecrypt() takes two parameters: the encrypted string and the passphrase. To decrypt the above example, you would simply code this:
decrypted = gpg.gpgDecrypt(variables.encrypted, "passphrase");
Published September 15, 2004 Reads 42,216
Copyright © 2004 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
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.
![]() |
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: |
||||
![]() |
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: |
||||
![]() |
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: 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? |
||||
![]() |
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. |
||||
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Adobe Flex Developer Earns $100K in New York City
- Adobe LiveCycle Enterprise Suite 2 for Cloud Computing
- Adobe Betas Target RIAs and Cloud Computing
- Adobe Cans Another 9% of its Workforce
- Moyea DVD4Web Converter V2.0 Converts DVD to FLV Fast and Synchronously with Watermarks
- Adobe Fiddles with its Web Apps
- Adobe & Salesforce Cut Cloud Deal
- Hosting.com Launches ColdFusion 9 in the Cloud
- The Real Time Infrastructure Ultimatum
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Eval JavaScript in a Global Context
- Fig Leaf Software to Exhibit at Government IT Conference & Expo
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Is Microsoft as Free as Open Source?
- Adobe Reader Sued
- The Planet Named “Bronze Sponsor” of Cloud Computing Expo
- Microsoft Expression Web Has Got Game
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Adobe Flex Developer Earns $100K in New York City
- Bruce Chizen Joins Voyager Capital as Venture Partner
- My Top Seven Wishes From Adobe MAX 2009
- The Next Programming Models, RIAs and Composite Applications
- Where Are RIA Technologies Headed in 2008?
- Constructing an Application with Flash Forms from the Ground Up
- AJAX World RIA Conference & Expo Kicks Off in New York City
- CFEclipse: The Developer's IDE, Eclipse For ColdFusion
- Personal Branding Checklist
- Adobe Flex 2: Advanced DataGrid
- Has the Technology Bounceback Begun?
- Building a Zip Code Proximity Search with ColdFusion
- i-Technology Viewpoint: We Need Not More Frameworks, But Better Programmers
- The Asynchronous CFML Gateway
- Web Services Using ColdFusion and Apache CXF
























