GenerateSymmetricKey

GenerateSymmetricKey[]

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

GenerateSymmetricKey["password"]

derives a SymmetricKey object from the password string given.

GenerateSymmetricKey[bytes]

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

GenerateSymmetricKey[DerivedKey[]]

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

GenerateSymmetricKey[opts]

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"
    "Blowfish"
    "CAST5"
  • 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.

Examples

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, https://reference.wolfram.com/language/ref/GenerateSymmetricKey.html (updated 2019).

Text

Wolfram Research (2015), GenerateSymmetricKey, Wolfram Language function, https://reference.wolfram.com/language/ref/GenerateSymmetricKey.html (updated 2019).

CMS

Wolfram Language. 2015. "GenerateSymmetricKey." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2019. https://reference.wolfram.com/language/ref/GenerateSymmetricKey.html.

APA

Wolfram Language. (2015). GenerateSymmetricKey. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/GenerateSymmetricKey.html

BibTeX

@misc{reference.wolfram_2024_generatesymmetrickey, author="Wolfram Research", title="{GenerateSymmetricKey}", year="2019", howpublished="\url{https://reference.wolfram.com/language/ref/GenerateSymmetricKey.html}", note=[Accessed: 18-December-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_generatesymmetrickey, organization={Wolfram Research}, title={GenerateSymmetricKey}, year={2019}, url={https://reference.wolfram.com/language/ref/GenerateSymmetricKey.html}, note=[Accessed: 18-December-2024 ]}