generateSecretKey

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

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

generateSecretKey Argument Reference

algorithm String

Values:
  • CFMX_COMPAT
  • 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 128 bit Key

Generate a 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);

Fork me on GitHub