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
    "Bitcoin","Ethereum"keys suitable for blockchains
  • 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 must always be included in the association:
  • "Type""RSA"type of keys to produce
  • Possible settings for "Type" are "RSA" and "EllipticCurve".
  • For RSA, the following elements can be given in the association:
  • "KeySize"2048target size of key in bits
    "PublicExponent"65537public exponent
    "Padding""PKCS1"padding mode
  • Possible settings for "Padding" include "OAEP", "PKCS1", "SSLV23", and None.
  • For RSA, the maximum length of data that can be encrypted is determined by the number of bytes in the modulus, and the padding mode according to:
  • "PKCS1"<b-11
    "SSLV23"<b-11
    "OAEP"<b-41
    Noneb
  • Encrypting with the private key and decrypting with the public key only works with the padding modes "PKCS1" and None.
  • 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
  • The "Bitcoin" and "Ethereum" settings for "CurveName" are equivalent to the "secp256k1" curve.

Examples

open all close all

Basic Examples  (2)

Generate corresponding public and private keys:

In[1]:=
Click for copyable input
Out[1]=

Encrypt using the public key:

In[2]:=
Click for copyable input
Out[2]=

Decrypt with the private key:

In[3]:=
Click for copyable input
Out[3]=

Alternatively, encrypt with the private key:

In[4]:=
Click for copyable input
Out[4]=

Decrypt with the public key:

In[5]:=
Click for copyable input
Out[5]=

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

In[1]:=
Click for copyable input
Out[1]=

Scope  (5)

Options  (6)

Applications  (2)

Possible Issues  (4)

Introduced in 2015
(10.1)
|
Updated in 2019
(12.0)