Wolfram Language & System 10.3 (2015)|Legacy Documentation

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

Encrypt

Encrypt["password",expr]
encrypts expr using the specified password, to give an encrypted object.

Encrypt[keyspec,expr]
encrypts expr using the cryptographic key specification keyspec.

DetailsDetails

  • Encrypt yields EncryptedObject[], suitable for decryption with Decrypt.
  • Encrypt[key,"string"] yields an EncryptedObject containing the encrypted version of the contents of the string as encoded in UTF-8.
  • Encrypt[key,ByteArray[]] yields an EncryptedObject containing the encrypted version of the raw bytes in the ByteArray object.
  • For block ciphers, Encrypt uses the OpenSSL PKCS padding method to pad out incomplete input blocks.
  • For a general expression, Encrypt[key,expr] yields an EncryptedObject essentially containing an encrypted version of Compress[expr].
  • For RSA ciphers, 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

ExamplesExamplesopen allclose all

Basic Examples  (3)Basic Examples  (3)

Encrypt a message with a password:

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

Show the raw encrypted form:

Decrypt with the password to get back the message:

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

Generate a key:

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

Encrypt using the key:

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

Generate 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 using the private key:

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

Alternatively, encrypt using the private key:

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

Now decrypt using the public key:

In[5]:=
Click for copyable input
Out[5]=
Introduced in 2015
(10.1)