Listing 1
<cfcomponent displayname="cfGnuPG" hint="ColdFusion wrapper for Java wrapper of
GnuPG.">
<cfproperty name="gpgRuntime" type="string" default="gpg" required="true"
hint="Absolute path of GnuPG runtime binaries.">
<cffunction name="init" access="public" output="No">
<cfargument name="gpgRuntime" required="No" type="string" default="gpg"
hint="Absolute path to GnuPG runtime binary. If none passed to the
constructor, the value ""gpg"" is used. Make sure this is in your PATH
variable if you are going to use this.">
<cfscript>
gpg = createObject("java", "com.sys_con.ColdFusion.GnuPG");
gpg.init(arguments.gpgRuntime);
</cfscript>
</cffunction>
<cffunction name="getRuntime" access="public" displayname="Get GnuPG Runtime
path." output="No" returntype="string" hint="Returns the GnuPG runtime path.">
<cfscript>
return gpg.getGnuPGRuntime();
</cfscript>
</cffunction>
<cffunction name="newKey" access="public" displayname="New Key" output="No"
returntype="string" hint="Creates a new GnuPG key pair. <span
class=""color: ##ff0000;"">Warning:</span> Generating key pairs is
slow...be patient.">
<cfargument name="realName" required="Yes" type="string" hint="Name for
the person for whom the key is being generated.">
<cfargument name="comment" required="Yes" type="string" hint="Name
comment (to help differentiate people with similar names).">
<cfargument name="email" required="Yes" type="string" hint="Email
address for the key.">
<cfargument name="expireDate" required="Yes" type="string" hint="Valid
values:<ul><li>0 --> key does not
expire</li><li><em>n</em> --> key expires in n
days</li><li><em>n</em>w --> key expires in n
weeks</li><li><em>n</em>m --> key expires in n
months</li><li><em>n</em>y --> key expires in n
years</li></ul>">
<cfargument name="passphrase" required="Yes" type="string" hint="Private
passphrase for the key pair.">
<cfscript>
return gpg.newKey(arguments.realName, arguments.comment,
arguments.email, arguments.expireDate, arguments.passphrase);
</cfscript>
</cffunction>
<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>
<cffunction name="gpgDecrypt" access="public" displayname="Decrypt"
hint="Decrypts data streams using GnuPG." output="No">
<cfargument name="str" required="Yes" type="string" hint="Data stream to
decrypt.">
<cfargument name="passphrase" required="Yes" type="string"
hint="Passphrase for decrypting data stream.">
<cfscript>
return gpg.decrypt(arguments.str, arguments.passphrase);
</cfscript>
</cffunction>
<cffunction name="sign" access="public" displayname="Sign" hint="Creates a
signature fingerprint." output="No">
<cfargument name="str" required="Yes" type="string" hint="Data stream to
sign.">
<cfargument name="passphrase" required="Yes" type="string"
hint="Passphrase for signature.">
<cfscript>
return gpg.sign(arguments.str, arguments.passphrase);
</cfscript>
</cffunction>
<cffunction name="signFile" access="public" displayname="Sign File"
hint="Creates a signature file for a given file.">
<cfargument name="filePath" required="Yes" type="string" hint="Path of
file to sign.">
<cfargument name="passphrase" required="Yes" type="string"
hint="Passphrase for signature.">
<!--- create a Java-safe path --->
<cfset filePath = replace(filePath, "\", "\\", "all")>
<cfscript>
return gpg.signFile(arguments.filePath, arguments.passphrase);
</cfscript>
</cffunction>
<!--- signature block not being returned --->
<cffunction name="clearSign" access="public" displayname="Clear Sign"
hint="Creates a clear signed fingerprint for a data stream.">
<cfargument name="str" required="Yes" type="string" hint="Data stream to
sign.">
<cfargument name="passphrase" required="Yes" type="string"
hint="Passphrase for signature.">
<cfscript>
return gpg.clearSign(arguments.str, arguments.passphrase);
</cfscript>
</cffunction>
<cffunction name="signAndEncrypt" access="public" displayname="Sign and
Encrypt" hint="Signs and encrypts a datastream." output="No">
<cfargument name="str" required="Yes" type="string" hint="Data stream to
sign.">
<cfargument name="keyID" required="Yes" type="string" hint="User key to
encrypt to.">
<cfargument name="passphrase" required="Yes" type="string"
hint="Passphrase for signature.">
<cfscript>
return gpg.signAndEncrypt(arguments.str, arguments.keyID,
arguments.passphrase);
</cfscript>
</cffunction>
<cffunction name="verifySignature" access="public" displayname="Verify
Signature" hint="Verifies a given signature's validity.">
<cfargument name="sig" required="Yes" type="string" hint="Signature to
verify.">
<cfscript>
return gpg.verifySignature(arguments.sig);
</cfscript>
</cffunction>
<cffunction name="verifyFile" access="public" displayname="Verify File"
hint="Verifies a given file's signature validity.">
<cfargument name="filePath" required="Yes" type="string" hint="Path to
file to verify.">
<cfscript>
return gpg.verifyFile(arguments.filePath);
</cfscript>
</cffunction>
<cffunction name="listKeys" access="public" displayname="List Public Keys"
hint="Returns all keys in hte public key ring." output="No">
<cfscript>
return gpg.listKeys();
</cfscript>
</cffunction>
<cffunction name="getKey" access="public" displayname="Get Key"
hint="Returns specified key from the public key ring.">
<cfargument name="keyID" required="Yes" type="string" hint="KeyID to
display">
<cfscript>
return gpg.listKeys(arguments.keyID);
</cfscript>
</cffunction>
<cffunction name="listSecretKeys" access="public" displayname="List Secret
Keys" hint="Returns all keys in the secret key ring." output="No">
<cfscript>
return gpg.listSecretKeys();
</cfscript>
</cffunction>
<cffunction name="getSecretKey" access="public" displayname="Get secret key"
hint="Returns the specified key from the secret keyring." output="No"
returntype="string">
<cfargument name="keyID" required="Yes" type="string" hint="KeyID to
display">
<cfscript>
return gpg.listSecretKeys(arguments.keyID);
</cfscript>
</cffunction>
<cffunction name="finger" access="public" displayname="List fingerprints"
hint="Returns all public keyring fingerprints." output="No"
returntype="string">
<cfscript>
return gpg.finger();
</cfscript>
</cffunction>
<cffunction name="getFinger" access="public" displayname="Get fingerprint"
hint="Returns the specified fingerprint from your public keyring." output="No"
returntype="string">
<cfargument name="keyID" required="Yes" type="string" hint="KeyID to
display">
<cfscript>
return gpg.finger(arguments.keyID);
</cfscript>
</cffunction>
<cffunction name="listSigs" access="public" displayname="List Signatures"
hint="Returns all signatures from your public keyring.">
<cfscript>
return gpg.listSigs();
</cfscript>
</cffunction>
<cffunction name="getPublicKey" access="public" displayname="Get Public Key"
hint="Returns the public key for the specified keyID.">
<cfargument name="keyID" required="Yes" type="string" hint="KeyID to
display">
<cfscript>
return gpg.getPublicKey(arguments.keyID);
</cfscript>
</cffunction>
<cffunction name="importKey" access="public" displayname="Import public
key." hint="Imports a key into your public keyring." returntype="string">
<cfargument name="key" required="Yes" type="string" hint="Key to
import">
<cfscript>
return gpg.importKey(arguments.key);
</cfscript>
</cffunction>
<cffunction name="dicewarePassphrase" access="public" displayname="Diceware
Passphrase" hint="Generates a Diceware passphrase using
java.security.SecureRandom." returntype="string" output="No">
<cfargument name="length" default="5" required="Yes" type="numeric">
<cfset var number = "">
<cfset var results = "">
<!--- get the word list --->
<cfhttp url="http://support.swem.wm.edu/tools/wordlist.txt" method="GET"
name="wordlist" delimiter=" " textqualifier=" "></cfhttp>
<!--- create words --->
<cfloop from="1" to="#arguments.length#" index="i">
<cfset number = rollDie(5)>
<!--- query wordlist for word --->
<cfquery name="word" dbtype="query">
SELECT word
FROM wordList
WHERE number = '#number#'
</cfquery>
<cfset results = results & " " & word.word>
</cfloop>
<cfreturn results>
</cffunction>
<cffunction name="rollDie" access="private" displayname="Roll Dice"
hint="Similates rolling dice to generate passphrases" output="No">
<cfargument name="rolls" required="No" default="5" type="numeric"
hint="Number of rolls">
<cfscript>
//create a Random number
rand = CreateObject("java", "java.security.SecureRandom");
result = "";
//loop over to create a 5 digit number
for(i = 0; i LT arguments.rolls; i = i + 1){
result = result & abs(rand.nextInt()) MOD 6 + 1;
}
return result;
</cfscript>
</cffunction>
</cfcomponent>