decryptBinary

Decrypts encrypted binary data with the specified key, value, algorithm, salt, and iterations.

decryptBinary(binaryData, key [, algorithm [, prefix [, iterations]]]) → returns binary

Argument Reference

binaryData string
Required

Binary data to decrypt.

key string
Required

Key or seed used to encrypt the string.
* For the CFMX_COMPAT algorithm, any combination of any number of characters; used as a seed used to generate a 32-bit encryption key.
* For all other algorithms, a key in the format used by the algorithm. For these algorithms, use the GenerateSecretKey function to generate the key.

algorithm string
Default: CFMX_COMPAT

The algorithm to use to decrypt the string. Must be the same as the algorithm used to encrypt the string. See the encrypt function for additional algorithms.
ColdFusion Standard Edition installs the following algorithms:
* CFMX_COMPAT: the algorithm used in ColdFusion MX and prior releases. This algorithm is the least secure option and not recommended. (default).
* AES: the Advanced Encryption Standard specified by the National Institute of Standards and Technology (NIST) FIPS-197.
* BLOWFISH: the Blowfish algorithm defined by Bruce Schneier.
* DES: the Data Encryption Standard algorithm defined by NIST FIPS-46-3.
* DESEDE: the "Triple DES" algorithm defined by NIST FIPS-46-3.

NOTE: ColdFusion Enterprise Edition installs RSA BSafe Crypto-J library, which provides FIPS-140 Compliant Strong Cryptography. This also includes:
* DESX: The extended Data Encryption Standard symmetric encryption algorithm.
* RC2: The RC2 block symmetric encryption algorithm defined by RFC 2268.
* RC4: The RC4 symmetric encryption algorithm.
* RC5: The RC5 encryption algorithm.
* PBE: Password-based encryption algorithm defined in PKCS #5.
* AES/GCM/NoPadding: Encryption algorithm.

NOTE: If you install additional cryptography algorithms, you can also specify any of its encryption and decryption algorithms.
Values:
  • CFMX_COMPAT
  • AES
  • BLOWFISH
  • DES
  • DESEDE
  • DESX
  • RC2
  • RC4
  • RC5
  • PBE
  • AES/GCM/NoPadding

prefix binary

The binary IV or salt that was used to encrypt the data, depending on the algorithm.
* For block encryption algorithms: the binary Initialization Vector. The algorithm must use a feedback mode other than ECB, and the value must be exactly the algorithm's block size.
* For password-based encryption (PBE) algorithms: the binary salt used to turn the password into a key.

NOTE: If you specify this parameter, you must also specify the algorithm parameter.

iterations numeric
Default: 0

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.

NOTE: If you specify this parameter, you must also specify the algorithm parameter with a Password Based Encryption (PBE) algorithm.
NOTE: This parameter is used with a salt passed in prefix. Do not specify this parameter for Block Encryption Algorithms.
NOTE: You must use the same value to encrypt and decrypt the data.

Compatibility

ColdFusion:

Version 7.0.1+ CF2018+ uses separate iv or salt named parameters.

Lucee:

Uses IVorSalt parameter or aliases of iv and salt.

Examples
Sample code invoking the decryptBinary function

Decrypts binary data that was encrypted with encryptBinary, using the same key and algorithm.

key = generateSecretKey( "AES" );
data = charsetDecode( "Hello World", "utf-8" );
encrypted = encryptBinary( data, key, "AES" );
decrypted = decryptBinary( encrypted, key, "AES" );
writeOutput( charsetEncode( decrypted, "utf-8" ) );

Expected Result: Hello World

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub