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.

Details

  • 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

Examples

open allclose all

Basic Examples  (3)

Encrypt a message with a password:

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

Show the raw encrypted form:

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

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]=

Scope  (2)

Applications  (2)

Properties & Relations  (1)

Possible Issues  (2)

See Also

Decrypt  EncryptFile  EncryptedObject  SymmetricKey  GenerateSymmetricKey  GenerateAsymmetricKeyPair  Hash  FieldMasked  CellularAutomaton  ShiftRegisterSequence  BinarySerialize

Introduced in 2015
(10.1)