- See Also
-
Related Guides
- Cryptographic Number Theory
- Working with Tezos Blockchains
- Working with Litecoin Blockchains
- Working with Ethereum Blockchains
- Working with Cardano Blockchains
- Working with bloxberg Blockchain
- Working with Bitcoin Cash Blockchains
- Working with Bitcoin Blockchains
- Working with ARK Blockchains
- Working with Blockchains
- Cryptography
- Workflows
-
- See Also
-
Related Guides
- Cryptographic Number Theory
- Working with Tezos Blockchains
- Working with Litecoin Blockchains
- Working with Ethereum Blockchains
- Working with Cardano Blockchains
- Working with bloxberg Blockchain
- Working with Bitcoin Cash Blockchains
- Working with Bitcoin Blockchains
- Working with ARK Blockchains
- Working with Blockchains
- Cryptography
- Workflows
randomly generates a PrivateKey and corresponding PublicKey object for use with public-key cryptographic functions.
GenerateAsymmetricKeyPair[type]
randomly generates private and public keys of the specified type.
GenerateAsymmetricKeyPair[opts]
randomly generates keys using the specified options.
GenerateAsymmetricKeyPair
randomly generates a PrivateKey and corresponding PublicKey object for use with public-key cryptographic functions.
GenerateAsymmetricKeyPair[type]
randomly generates private and public keys of the specified type.
GenerateAsymmetricKeyPair[opts]
randomly generates keys using the specified options.
Details and Options
- GenerateAsymmetricKeyPair returns an association of the form <|"PrivateKey"…,"PublicKey" …|>.
- GenerateAsymmetricKeyPair[] by default uses the "RSA" type, with a system-specific, high-entropy randomness source.
- In GenerateAsymmetricKeyPair[type], the following types can be specified:
-
"RSA" RSA with default parameters "EllipticCurve" elliptic curve secp256k1 "EdwardsCurve" twisted Edwards curve ed25519 "Bitcoin","Ethereum" keys suitable for blockchains Method"curve" named elliptic curve - GenerateAsymmetricKeyPair has the following option:
-
Method Automatic details of key generation method - With the setting Method->assoc, the association assoc gives details of the key generation method to use.
- The following element should be included in the association:
-
"Type" "RSA" type of keys to produce - Possible settings for "Type" are "RSA" , "EllipticCurve" and "EdwardsCurve".
- For "RSA", the following elements can be given in the association:
-
"KeySize" 2048 target size of key in bits "PublicExponent" 65537 public exponent - For "EllipticCurve", the following elements can be given in the association:
-
"CurveName" "secp256k1" elliptic curve to use "Compressed" False whether the public key is in compressed form - For "EdwardsCurve", the following elements can be given in the association:
-
"CurveName" "ed25519" twisted Edwards curve to use - Possible settings for "CurveName" and Methodcurve are listed in $CryptographicEllipticCurveNames.
- "Bitcoin" uses "CurveName""secp256k1" and "Compressed"True.
- "Ethereum" uses "CurveName""secp256k1" and "Compressed"False.
Examples
open all close allBasic Examples (3)
Generate corresponding public and private keys:
keys = GenerateAsymmetricKeyPair[]Encrypt[keys["PublicKey"], "Now is the time..."]Decrypt[keys["PrivateKey"], %]Alternatively, encrypt with the private key:
Encrypt[keys["PrivateKey"], "Now is the time..."]Decrypt[keys["PublicKey"], %]Generate an elliptic curve key pair using the default curve secp256k1:
GenerateAsymmetricKeyPair["EllipticCurve"]Generate a twisted Edwards elliptic curve key pair using the default curve ed25519:
GenerateAsymmetricKeyPair["EdwardsCurve"]Scope (6)
Default Method (1)
Named Methods (4)
GenerateAsymmetricKeyPair["RSA"]Generate an elliptic curve key pair using the default curve secp256k1:
GenerateAsymmetricKeyPair["EllipticCurve"]Generate a twisted Edwards elliptic curve key pair using the default curve ed25519:
GenerateAsymmetricKeyPair["EdwardsCurve"]Generate key pairs compatible with cryptocurrency networks:
GenerateAsymmetricKeyPair["Bitcoin"]GenerateAsymmetricKeyPair["Ethereum"]Particular Settings (1)
Provide an association with particular settings in the Method option:
GenerateAsymmetricKeyPair[Method -> <|"Type" -> "EllipticCurve", "CurveName" -> "secp521r1", "Compressed" -> False|>]GenerateAsymmetricKeyPair[Method -> <|"Type" -> "EdwardsCurve", "CurveName" -> "ed448"|>]Options (6)
Method (6)
Generate a key pair with a 4096-bit key:
GenerateAsymmetricKeyPair[Method -> <|"Type" -> "RSA", "KeySize" -> 4096|>]Generate a key pair with a public exponent of 17:
GenerateAsymmetricKeyPair[Method -> <|"Type" -> "RSA", "PublicExponent" -> 17|>]Generate a Bitcoin key pair with a compressed public key:
GenerateAsymmetricKeyPair[Method -> <|"Type" -> "EllipticCurve", "CurveName" -> "Bitcoin", "Compressed" -> True|>]Generate an Ethereum key pair with an uncompressed public key:
GenerateAsymmetricKeyPair[Method -> <|"Type" -> "EllipticCurve", "CurveName" -> "Ethereum", "Compressed" -> False|>]Generate a twisted Edwards curve–based key specifying a particular curve name:
GenerateAsymmetricKeyPair[Method -> <|"Type" -> "EdwardsCurve", "CurveName" -> "ed448"|>]Generate an elliptic curve–based key pair using a curve name as method:
GenerateAsymmetricKeyPair[Method -> "prime192v1"]GenerateAsymmetricKeyPair[Method -> "ed448"]Applications (2)
Generate a personal pair of elliptic curve–based keys to sign and verify a message using the Elliptic Curve Digital Signature Algorithm:
keys = GenerateAsymmetricKeyPair["EllipticCurve"]Generate a digital signature using your private key:
message = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks";signature = GenerateDigitalSignature[message, keys["PrivateKey"]]Verify a digital signature using your public key:
VerifyDigitalSignature[{message, signature}, keys["PublicKey"]]Write simple RSA-based signing and verification functions:
sign[key_PrivateKey, expr_] := Encrypt[key, Hash[expr, "SHA256"]]verify[key_PublicKey, expr_, signature_EncryptedObject] := Decrypt[key, signature] === Hash[expr, "SHA256"]Generate a pair of public and private RSA keys:
keys = GenerateAsymmetricKeyPair[]expr = Graphics[Disk[]]sig = sign[keys["PrivateKey"], expr]Verify that the signature is authentic:
verify[keys["PublicKey"], expr, sig]Verifying with another expression will fail:
verify[keys["PublicKey"], "another expression", sig]Possible Issues (2)
Incompatible Private Keys (1)
Related Guides
-
▪
- Cryptographic Number Theory ▪
- Working with Tezos Blockchains ▪
- Working with Litecoin Blockchains ▪
- Working with Ethereum Blockchains ▪
- Working with Cardano Blockchains ▪
- Working with bloxberg Blockchain ▪
- Working with Bitcoin Cash Blockchains ▪
- Working with Bitcoin Blockchains ▪
- Working with ARK Blockchains ▪
- Working with Blockchains ▪
- Cryptography
Related Workflows
Text
Wolfram Research (2015), GenerateAsymmetricKeyPair, Wolfram Language function, https://reference.wolfram.com/language/ref/GenerateAsymmetricKeyPair.html (updated 2020).
CMS
Wolfram Language. 2015. "GenerateAsymmetricKeyPair." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/GenerateAsymmetricKeyPair.html.
APA
Wolfram Language. (2015). GenerateAsymmetricKeyPair. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/GenerateAsymmetricKeyPair.html
BibTeX
@misc{reference.wolfram_2026_generateasymmetrickeypair, author="Wolfram Research", title="{GenerateAsymmetricKeyPair}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/GenerateAsymmetricKeyPair.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_generateasymmetrickeypair, organization={Wolfram Research}, title={GenerateAsymmetricKeyPair}, year={2020}, url={https://reference.wolfram.com/language/ref/GenerateAsymmetricKeyPair.html}, note=[Accessed: 12-June-2026]}