Wolfram Language & System 11.0 (2016)|Legacy Documentation

This is documentation for an earlier version of the Wolfram Language.View current documentation (Version 11.2)

GenerateAsymmetricKeyPair

GenerateAsymmetricKeyPair[]
randomly generates a PrivateKey and corresponding PublicKey object for use with public-key cryptographic functions.

GenerateAsymmetricKeyPair[opts]
randomly generates private and public keys using the specified options.

Details and OptionsDetails and Options

  • GenerateAsymmetricKeyPair returns an association of the form <|"PrivateKey"->,"PublicKey"->|>.
  • GenerateAsymmetricKeyPair[] uses a system-specific, high-entropy randomness source.
  • GenerateAsymmetricKeyPair has a Method option that specifies the cryptography method to use.
  • The only cipher currently supported is RSA.
  • Particular settings can be specified using Method->assoc, where the entries in the association assoc are:
  • "Cipher""RSA"cipher to use
    "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"
    "SSLV23"
    "OAEP"
    None
  • Encrypting with the private key and decrypting with the public key only works with the padding modes "PKCS1" and None.

ExamplesExamplesopen allclose all

Basic Examples  (1)Basic Examples  (1)

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]=
Introduced in 2015
(10.1)