randomly generates a SymmetricKey object suitable for use with cryptographic functions.


derives a SymmetricKey object from the password string given.


generates a SymmetricKey object using the byte array or list of bytes directly as the key.


generates a symmetric key object with a key given by the DerivedKey object.


randomly generates a symmetric key using the specified options.

Details and Options

  • GenerateSymmetricKey[] uses a system-specific, high-entropy randomness source.
  • GenerateSymmetricKey has a Method option that specifies the cryptography method to use.
  • With Method->"cipher", default settings for the specified cipher are used.
  • If Method option is not provided, the default cipher is used. The current default cipher is "AES256".
  • Particular settings can be specified using Method->assoc, where the entries in the association assoc are:
  • "Cipher""AES256"cipher to use
    "KeySize"Automaticsize of key in bits
  • Supported ciphers, together with the default key size, include:
  • "Blowfish"256 bits
    "CAST5"256 bits
    "DES"64 bits
    "RC4"256 bits
    "IDEA"128 bits
    "AES128"128 bits
    "AES192"192 bits
    "AES256"256 bits
  • The following ciphers can use any key size that is a multiple of 8:
  • "RC4"
  • GenerateSymmetricKey["password"] effectively uses GenerateDerivedKey to generate a key.
  • In GenerateSymmetricKey[bytes], bytes can be a ByteArray object or a list of integers between 0 and 255. The length of bytes must match the key size of the cipher used.


open allclose all

Basic Examples  (1)

Generate a random symmetric key:

Use the key to encrypt:

Scope  (3)

Derive a symmetric key from a password:

Methods  (2)

Generate a symmetric key appropriate for encryption using Blowfish:

A simplified syntax:

Generate a symmetric key with a key size of 512 bits:

Possible Issues  (1)

The key size must be a multiple of 8:

Only some ciphers allow a variable key size:

Wolfram Research (2015), GenerateSymmetricKey, Wolfram Language function, (updated 2019).


Wolfram Research (2015), GenerateSymmetricKey, Wolfram Language function, (updated 2019).


Wolfram Language. 2015. "GenerateSymmetricKey." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2019.


Wolfram Language. (2015). GenerateSymmetricKey. Wolfram Language & System Documentation Center. Retrieved from


@misc{reference.wolfram_2024_generatesymmetrickey, author="Wolfram Research", title="{GenerateSymmetricKey}", year="2019", howpublished="\url{}", note=[Accessed: 18-May-2024 ]}


@online{reference.wolfram_2024_generatesymmetrickey, organization={Wolfram Research}, title={GenerateSymmetricKey}, year={2019}, url={}, note=[Accessed: 18-May-2024 ]}