GenerateDerivedKey
✖
GenerateDerivedKey
Details and Options


- GenerateDerivedKey uses a computation-intensive key derivation function to generate a cryptographically strong key hash.
- password and salt can be strings, lists of integers representing byte values or ByteArray objects.
- GenerateDerivedKey[password] is equivalent to GenerateDerivedKey[password,Automatic]. If salt is not provided, it is randomly generated.
- GenerateDerivedKey takes a Method option, which uses an Association to specify a key derivation function and parameters.
- Typical settings for Method include:
-
"Function" key derivation function "FunctionParameters" key derivation function parameters - Supported key derivation functions are: "scrypt", "Argon2d", "Argon2i", "Argon2id".
- Function parameters for the "scrypt" key derivation function are an Association, which includes:
-
"KeySize" 64 desired key length in bytes "N" 2^15 computational cost factor "r" 8 block size factor "p" 1 parallelization factor - The value of "N" must be an integer power of 2 greater than 1.
- Function parameters for the "Argon2x" key derivation functions are an Association, which includes:
-
"KeySize" 64 desired key length in bytes "t" 2 number of iterations "m" 2^16 memory size to use in kibibytes "p" 1 parallelization factor - The value of "m" must be an integer power of 2.
- To generate a cryptographically secure key, parameters of the key derivation function are usually adjusted for the computation on a specific computer to take just below a fraction of a second.
Examples
open allclose allBasic Examples (2)Summary of the most common use cases
Scope (8)Survey of the scope of standard use cases
Generate a derived key using a list of integers as a password:

https://wolfram.com/xid/0tqhjc7gjje4ib-1qf5z

Generate a derived key using ByteArray as a password:

https://wolfram.com/xid/0tqhjc7gjje4ib-bbcxm6

Generate a derived key using a list of integers as a salt:

https://wolfram.com/xid/0tqhjc7gjje4ib-ehspm

Customize the parameters for the default "scrypt" method:

https://wolfram.com/xid/0tqhjc7gjje4ib-jlkct

Use an alternate key derivation function to generate a derived key:

https://wolfram.com/xid/0tqhjc7gjje4ib-hufcui

Specify a key derivation function and parameters:

https://wolfram.com/xid/0tqhjc7gjje4ib-kqqkyg

Generate string representation of DerivedKey:

https://wolfram.com/xid/0tqhjc7gjje4ib-jmssba

Reconstruct the key from its string representation using DerivedKey:

https://wolfram.com/xid/0tqhjc7gjje4ib-r0qv4v

The new key is identical to the original:

https://wolfram.com/xid/0tqhjc7gjje4ib-6msudi

Generate a ByteArray from the password:

https://wolfram.com/xid/0tqhjc7gjje4ib-bv3v76

Options (2)Common values & functionality for each option
Method (2)
If only the key "FunctionParameters" is specified, it customizes the default method "scrypt":

https://wolfram.com/xid/0tqhjc7gjje4ib-ilj09t

Use the alternate key derivation function "Argon2id" with default parameters:

https://wolfram.com/xid/0tqhjc7gjje4ib-syp1y0

Specify the parameters as well:

https://wolfram.com/xid/0tqhjc7gjje4ib-rv4v1y

Applications (3)Sample problems that can be solved with this function
Generate cryptographically strong password hash from a simple password string:

https://wolfram.com/xid/0tqhjc7gjje4ib-h99im4


https://wolfram.com/xid/0tqhjc7gjje4ib-eo6mcw


https://wolfram.com/xid/0tqhjc7gjje4ib-gtahr2

Verify the password using derived key in the string representation:

https://wolfram.com/xid/0tqhjc7gjje4ib-gk9kla


https://wolfram.com/xid/0tqhjc7gjje4ib-ku06mz

Properties & Relations (3)Properties of the function, and connections to other functions
DerivedKey is generated deterministically from the given the same password and salt:

https://wolfram.com/xid/0tqhjc7gjje4ib-ga4wdg

This also applies to generating keys from their string representation:

https://wolfram.com/xid/0tqhjc7gjje4ib-5kxnk

Computation time increases linearly with "r" in "scrypt":

https://wolfram.com/xid/0tqhjc7gjje4ib-cgpaqg

It increases linearly in "p" as well:

https://wolfram.com/xid/0tqhjc7gjje4ib-fxeg4o

Generate SymmetricKey from DerivedKey:

https://wolfram.com/xid/0tqhjc7gjje4ib-h6fhib


https://wolfram.com/xid/0tqhjc7gjje4ib-ch5sqz

Possible Issues (4)Common pitfalls and unexpected behavior
For certain parameters, generation of derived key may take significant time:

https://wolfram.com/xid/0tqhjc7gjje4ib-h016lc


https://wolfram.com/xid/0tqhjc7gjje4ib-cnnaw

Parameters of key derivation function must be machine-size integers:

https://wolfram.com/xid/0tqhjc7gjje4ib-ks4kj


Some key derivation functions have restrictions on password and salt sizes:

https://wolfram.com/xid/0tqhjc7gjje4ib-c4r6cf



https://wolfram.com/xid/0tqhjc7gjje4ib-cyijcs

When creating a symmetric key, random data taken from a derived key may be truncated to fit the new key size:

https://wolfram.com/xid/0tqhjc7gjje4ib-jvg97t


https://wolfram.com/xid/0tqhjc7gjje4ib-fzxr7u


https://wolfram.com/xid/0tqhjc7gjje4ib-fnwue3


In order to generate a derived key of the desired size, the key size must be specified explicitly:

https://wolfram.com/xid/0tqhjc7gjje4ib-b64ovn

Wolfram Research (2019), GenerateDerivedKey, Wolfram Language function, https://reference.wolfram.com/language/ref/GenerateDerivedKey.html (updated 2020).
Text
Wolfram Research (2019), GenerateDerivedKey, Wolfram Language function, https://reference.wolfram.com/language/ref/GenerateDerivedKey.html (updated 2020).
Wolfram Research (2019), GenerateDerivedKey, Wolfram Language function, https://reference.wolfram.com/language/ref/GenerateDerivedKey.html (updated 2020).
CMS
Wolfram Language. 2019. "GenerateDerivedKey." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/GenerateDerivedKey.html.
Wolfram Language. 2019. "GenerateDerivedKey." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/GenerateDerivedKey.html.
APA
Wolfram Language. (2019). GenerateDerivedKey. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/GenerateDerivedKey.html
Wolfram Language. (2019). GenerateDerivedKey. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/GenerateDerivedKey.html
BibTeX
@misc{reference.wolfram_2025_generatederivedkey, author="Wolfram Research", title="{GenerateDerivedKey}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/GenerateDerivedKey.html}", note=[Accessed: 08-July-2025
]}
BibLaTeX
@online{reference.wolfram_2025_generatederivedkey, organization={Wolfram Research}, title={GenerateDerivedKey}, year={2020}, url={https://reference.wolfram.com/language/ref/GenerateDerivedKey.html}, note=[Accessed: 08-July-2025
]}