generateSecretKey

Generates a secure random key value for use in the encrypt and decrypt functions.

generateSecretKey([algorithm] [,keysize]) → returns string

Argument Reference

algorithm string

The encryption algorithm used to generate the key.
NOTE: You cannot use generateSecretKey() to create a key for the CFMX_COMPAT default algorithm in encrypt() and decrypt() functions.
Values:
  • AES
  • BLOWFISH
  • DES
  • DESEDE

keysize numeric
Default: 128

Number of bits requested in the key for the specified algorithm (when allowed by JDK).
Values:
  • 128
  • 192
  • 256
  • 512

Links more information about generateSecretKey

Examples
Sample code invoking the generateSecretKey function

Generate an AES key and use it to encrypt and decrypt a secret.

ex={};
ex.key = generateSecretKey("AES");
ex.secret = "top secret";
ex.encrypted=encrypt(ex.secret, ex.key, "AES", "Base64");
ex.decrypted=decrypt(ex.encrypted, ex.key, "AES", "Base64");
writeDump(ex);

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

Fork me on GitHub