Decrypts a string that is encrypted using a standard encryption technique, including strings encrypted by the Encrypt
function.
An unencrypted string.
Security functions, String functions
Decrypt
(encrypted_string, key[,algorithm
[,encoding
]])
ColdFusion MX 7: Added the algorithm
and encoding
parameters.
Parameter | Description |
---|---|
encrypted_string |
String to decrypt. |
key |
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. |
algorithm |
(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:
If you install a security provider with additional cryptography algorithms, you can also specify any of its string encryption and decryption algorithms. |
encoding |
(Optional; if you specify this parameter, you must also specify the
|
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.
ColdFusion MX 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.
<h3>Decrypt Example</h3>
<!--- Do the following if the form has been submitted. --->
<cfif IsDefined("Form.myString")>
<cfscript>
/* GenerateSecretKey does not generate key for the CFMX_COMPAT algorithm,
so use the key from the form.
*/
if (Form.myAlgorithm EQ "CFMX_COMPAT")
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);
</cfscript>
<!--- Display the values used for encryption and decryption,
and the results. --->
<cfoutput>
<b>The algorithm:</b> #Form.myAlgorithm#<br>
<b>The key:</B> #theKey#<br>
<br>
<b>The string:</b> #Form.myString# <br>
<br>
<b>Encrypted:</b> #encrypted#<br>
<br>
<b>Decrypted:</b> #decrypted#<br>
</cfoutput>
</cfif>
<!--- The input form. --->
<form action="#CGI.SCRIPT_NAME#" method="post">
<b>Select the encoding</b><br>
<select size="1" name="myEncoding" >
<option selected>UU</option>
<option>Base64</option>
<option>Hex</option>
</select><br>
<br>
<b>Select the algorithm</b><br>
<select size="1" name="myAlgorithm" >
<option selected>CFMX_COMPAT</option>
<option>AES</option>
<option>DES</option>
<option>DESEDE</option>
</select><br>
<br>
<b>Input your key</b> (used for CFMX_COMPAT encryption only)<br>
<input type = "Text" name = "myKey" value = "MyKey"><br>
<br>
<b>Enter string to encrypt</b><br>
<textArea name = "myString" cols = "40" rows = "5" WRAP = "VIRTUAL">This string will be encrypted (you can replace it with more typing).
</textArea><br>
<input type = "Submit" value = "Encrypt my String">
</form>