Whatever message this page gives is out now! Go check it out!
| EncryptBinary(binaryData, key, algorithm, IV_Salt, iterations) |
Parameter | Description |
bytes | Binary data to encrypt. |
key | String. Key or seed used to encrypt the string.
|
algorithm | (Optional) The algorithm to use to decrypt the string.The Enterprise Edition of ColdFusion installs the RSA BSafe Crypto-J library, which provides FIPS-140 Compliant Strong Cryptography. For a list of algorithms, see the Encrypt function.The Standard Edition of ColdFusion installs a cryptography library with the following algorithms:
|
IVorSalt | (Optional) Specify this parameter to adjust ColdFusion encryption to match the details of other encryption software. If you specify this parameter, also specify the algorithm parameter.
|
iterations | (Optional) The number of iterations to transform the password into a binary key. Specify this parameter to adjust ColdFusion encryption to match the details of other encryption software. If you specify this parameter, also specify the algorithm parameter with a Password Based Encryption (PBE) algorithm. Do not specify this parameter for Block Encryption algorithms. Use the same value to encrypt and decrypt the data. |
<h3>EncryptBinary Example</h3>
<!--- Do the following if the form has been submitted. --->
<cfif IsDefined("Form.myfile")>
<cffile file="#Form.myfile#" action="readBinary" variable="myData">
<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=encryptBinary(myData, theKey, Form.myAlgorithm);
//Decrypt it
decrypted=decryptBinary(encrypted, theKey, Form.myAlgorithm);
</cfscript>
<cfset encfile="#Form.myfile#" & "_enc">
<cfset decfile="#Form.myfile#" & "_dec">
<cffile file="#encfile#" action="write" output="#encrypted#">
<cffile file="#decfile#" action="write" output="#decrypted#">
<!--- 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 InputFile:</b> #Form.myfile# <br>
<br>
<b>Encrypted:</b> #encfile#<br>
<br>
<b>Decrypted:</b> #decfile#<br>
</cfoutput>
</cfif>
<!--- The input form. --->
<form action="#CGI.SCRIPT_NAME#" method="post">
<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 filename to encrypt</b><br>
<input type="text" name="myfile" value="Enter the path of the file to encrypt"><br>
<input type = "Submit" value = "Encrypt file ">
</form><cfscript>
// binary data
b = ToBinary("abcd")
// generate the key
key = GenerateSecretKey("AES")
iterations="AssoicatedData"
randomIntegers = [];
// generate the SALT value
for ( i = 1 ; i <= 12 ; i++ ) {
arrayAppend( randomIntegers, randRange( -128, 127, "SHA1PRNG" ) );
}
initializationVector = javaCast( "byte[]", randomIntegers )
// encrypt srring
enc1 = EncryptBinary(binaryData=b,
key=key,
algorithm="AES/GCM/NoPadding",
IV_Salt=initializationVector,
iterations=iterations)
writeDump(enc1)
</cfscript>