<html>
<head>
<link href="mmres://user_interface_reference.css" rel="stylesheet" type="text/css">
<title>DECRYPT</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">DECRYPT</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>
Decrypts a string that is encrypted using a standard encryption technique, including strings encrypted by 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>
An unencrypted string. 
</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>Decrypt(encrypted_string, key[, algorithm[, encoding]])
</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>
Duplicate, Encrypt
</p>

<p>
ColdFusion&#160;MX&#160;7: Added the algorithm and encoding parameters.
</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>
This function uses a symmetric key-based algorithm, in which the same key is used to encrypt and decrypt a string. The parameter values must match the values used to encode string. The security of the encrypted string depends on maintaining the secrecy of the key. 
</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><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 key for the CFMX_COMPAT algorithm,
        so use the 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;MyKey&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="ENCRYPTED_STRING">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">ENCRYPTED_STRING</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>String to decrypt.</p>

  </td>
  </tr>
  </table>
</div>
<div id="KEY">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">KEY</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>String. For the CFMX_COMPAT algorithm, the seed that was used to encrypt the string; for all other algorithms, the key that was used to encrypt the string.</p>

  </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>(Optional) The algorithm to use to decrypt the string. Must be the same as the algorithm used to encrypt the string. ColdFusion MX installs a cryptography library with the following algorithms:</p><ul>

<li>CFMX_COMPAT: the algorithm used in ColdFusion MX and prior releases. This algorithm is the least secure option (default).</li>

<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>

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

<p>If you install a security provider with additional cryptography algorithms, you can also specify any of its string encryption and decryption algorithms.</p>

  </td>
  </tr>
  </table>
</div>
<div id="ENCODING">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">ENCODING</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>(Optional; if you specify this parameter, you must also specify the algorithm parameter.) The binary encoding used to represent the data as a string. Must be the same as the algorithm used to encrypt the string. </p><ul>

<li>Base64: the Base64 algorithm, as specified by IETF RFC 2045.</li>

<li>Hex: the characters A-F and 0-9 represent the hexadecimal byte values.</li>

<li>UU: the UNIX standard UUEncode algorithm (default) .</li>
</ul>


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

  </body>
</html>
