GenerateAsymmetricKeyPair

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:
  • MethodAutomaticdetails 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"2048target size of key in bits
    "PublicExponent"65537public exponent
  • For "EllipticCurve", the following elements can be given in the association:
  • "CurveName""secp256k1"elliptic curve to use
    "Compressed"Falsewhether 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 allclose all

Basic Examples  (3)

Generate corresponding public and private keys:

Encrypt using the public key:

Decrypt with the private key:

Alternatively, encrypt with the private key:

Decrypt with the public key:

Generate an elliptic curve key pair using the default curve secp256k1:

Generate a twisted Edwards elliptic curve key pair using the default curve ed25519:

Scope  (6)

Default Method  (1)

Generate a key pair without arguments, using RSA as the default method:

Named Methods  (4)

Generate an RSA key pair:

Generate an elliptic curve key pair using the default curve secp256k1:

Generate a twisted Edwards elliptic curve key pair using the default curve ed25519:

Generate key pairs compatible with cryptocurrency networks:

Particular Settings  (1)

Provide an association with particular settings in the Method option:

Options  (6)

Method  (6)

Generate a key pair with a 4096-bit key:

Generate a key pair with a public exponent of 17:

Generate a Bitcoin key pair with a compressed public key:

Generate an Ethereum key pair with an uncompressed public key:

Generate a twisted Edwards curvebased key specifying a particular curve name:

Generate an elliptic curvebased key pair using a curve name as method:

Applications  (2)

Generate a personal pair of elliptic curvebased keys to sign and verify a message using the Elliptic Curve Digital Signature Algorithm:

Generate a digital signature using your private key:

Verify a digital signature using your public key:

Write simple RSA-based signing and verification functions:

Generate a pair of public and private RSA keys:

Define an expression to sign:

Generate a signature:

Verify that the signature is authentic:

Verifying with another expression will fail:

Possible Issues  (2)

Incompatible Private Keys  (1)

Encryption with elliptic curvebased keys is not currently supported:

Timing  (1)

Generating larger keys takes longer:

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

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_2024_generateasymmetrickeypair, author="Wolfram Research", title="{GenerateAsymmetricKeyPair}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/GenerateAsymmetricKeyPair.html}", note=[Accessed: 21-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_generateasymmetrickeypair, organization={Wolfram Research}, title={GenerateAsymmetricKeyPair}, year={2020}, url={https://reference.wolfram.com/language/ref/GenerateAsymmetricKeyPair.html}, note=[Accessed: 21-November-2024 ]}