<html>
<head>
<link href="mmres://user_interface_reference.css" rel="stylesheet" type="text/css">
<title>GENERATESECRETKEY</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
   <div id="Description">
   <table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
      <tr> 
         <td valign="top" class="name">GENERATESECRETKEY</td>
         <td valign="top" nowrap class="compatibility">&nbsp;</td>
      </tr>
      <tr>
         <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
      </tr>


    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Description</span>
<p>
Gets a secure key value for use in the Encrypt function. 
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Returns</span>
<p>
A string containing the encryption key.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Category</span>
<p>
Security functions, String functions
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Function syntax</span><pre>GenerateSecretKey(<i>algorithm</i>)
</pre>    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">See also</span>
<p>
Decrypt, Encrypt
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">History</span>
<p>
ColdFusion&#160;MX&#160;7: Added this function.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Parameters</span>
<p>

</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Usage</span>
<p>
You cannot use the GenerateSecretKey function to generate a key for the ColdFusion default encryption algorithm (CFMX_COMPAT) of the Encrypt and Decrypt functions.
</p>

<p>
ColdFusion&#160;MX&#160;7 uses the Java Cryptography Extension (JCE) and installs a Sun Java 1.4.2 runtime that includes the Sun JCE default security provider. This provider includes the algorithms listed in the Parameters section. The JCE framework includes facilities for using other provider implementations; however, Macromedia cannot provide technical support for third-party security providers.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Example</span>
<p>
The following example encrypts and decrypts a text string. It lets you specify the encryption algorithm and encoding technique. It also has a field for a key seed to use with the CFMX_COMPAT algorithm. For all other algorithms, it uses the GenerateSecretKey function to generate a secret key.
</p>
<pre>&lt;h3&gt;Decrypt Example&lt;/h3&gt;

&lt;!--- Do the following if the form has been submitted. ---&gt;
&lt;cfif IsDefined(&quot;Form.myString&quot;)&gt;
   &lt;cfscript&gt;
      /* GenerateSecretKey does not generate keys for the CFMX_COMPAT algorithm,
      &#160;&#160;so we use a key from the form.
      */
      if (Form.myAlgorithm EQ &quot;CFMX_COMPAT&quot;)
         theKey=Form.MyKey;
      // For all other encryption techniques, generate a secret key.
      else
         theKey=generateSecretKey(Form.myAlgorithm);
      //Encrypt the string.
      encrypted=encrypt(Form.myString, theKey, Form.myAlgorithm,
         Form.myEncoding);
      //Decrypt it.
      decrypted=decrypt(encrypted, theKey, Form.myAlgorithm, Form.myEncoding);
   &lt;/cfscript&gt;

   &lt;!--- Display the values used for encryption and decryption, 
         and the results. ---&gt;
   &lt;cfoutput&gt;
      &lt;b&gt;The algorithm:&lt;/b&gt; #Form.myAlgorithm#&lt;br&gt;
      &lt;b&gt;The key:&lt;/B&gt; #theKey#&lt;br&gt;
      &lt;br&gt;
      &lt;b&gt;The string:&lt;/b&gt; #Form.myString# &lt;br&gt;
      &lt;br&gt;
      &lt;b&gt;Encrypted:&lt;/b&gt; #encrypted#&lt;br&gt;
      &lt;br&gt;
      &lt;b&gt;Decrypted:&lt;/b&gt; #decrypted#&lt;br&gt;
   &lt;/cfoutput&gt;
&lt;/cfif&gt;

&lt;!--- The input form. ---&gt;
&lt;form action=&quot;#CGI.SCRIPT_NAME#&quot; method=&quot;post&quot;&gt;
   &lt;b&gt;Select the encoding&lt;/b&gt;&lt;br&gt;
   &lt;select size=&quot;1&quot; name=&quot;myEncoding&quot; &gt;
      &lt;option selected&gt;UU&lt;/option&gt;
      &lt;option&gt;Base64&lt;/option&gt;
      &lt;option&gt;Hex&lt;/option&gt;
   &lt;/select&gt;&lt;br&gt;
   &lt;br&gt;
   &lt;b&gt;Select the algorithm&lt;/b&gt;&lt;br&gt;
   &lt;select size=&quot;1&quot; name=&quot;myAlgorithm&quot; &gt;
      &lt;option selected&gt;CFMX_COMPAT&lt;/option&gt;
      &lt;option&gt;AES&lt;/option&gt;
      &lt;option&gt;DES&lt;/option&gt;
      &lt;option&gt;DESEDE&lt;/option&gt;
   &lt;/select&gt;&lt;br&gt;
   &lt;br&gt;
   &lt;b&gt;Input your key&lt;/b&gt; (used for CFMX_COMPAT encryption only)&lt;br&gt;
   &lt;input type = &quot;Text&quot; name = &quot;myKey&quot; value = &quot;foobar&quot;&gt;&lt;br&gt;
   &lt;br&gt;
   &lt;b&gt;Enter string to encrypt&lt;/b&gt;&lt;br&gt;
   &lt;textArea name = &quot;myString&quot; cols = &quot;40&quot; rows = &quot;5&quot; WRAP = &quot;VIRTUAL&quot;&gt;This 
string will be encrypted (you can replace it with more typing).
   &lt;/textArea&gt;&lt;br&gt;
   &lt;input type = &quot;Submit&quot; value = &quot;Encrypt my String&quot;&gt;
&lt;/form&gt;
</pre>
         </td>
      </tr>
   </table>
   </div>
<div id="ALGORITHM">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">ALGORITHM</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>


<p>The encryption algorithm for which to generate the key. ColdFusion MX installs a cryptography library with the following algorithms:</p><ul>

<li>AES: the Advanced Encryption Standard specified by the National Institute of Standards and Technology (NIST) FIPS-197.</li>

<li>BLOWFISH: the Blowfish algorithm defined by Bruce Schneier.</li>

<li>DES: the Data Encryption Standard algorithm defined by NIST FIPS-46-3.</li>
</ul>

<p>DESEDE: the &quot;Triple DES&quot; algorithm defined by NIST FIPS-46-3.</p>

  </td>
  </tr>
  </table>
</div>

  </body>
</html>
