Encrypt
Details and Options



- 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 a general expression, Encrypt[key,expr] yields an EncryptedObject essentially containing an encrypted version of Compress[expr].
- The encryption method is based on the cipher and parameters of the key. See GenerateSymmetricKey and GenerateAsymmetricKeyPair for details.
- In a notebook interface, Encrypt[expr] generates a dialog box; in a textual interface it generates a textual prompt.
- Encrypt has the following option:
-
Method Automatic details of encryption method - With the setting Methodassoc, the association assoc gives details of the encryption method to use.
- The following elements can be given in the association assoc:
-
"Padding" Automatic padding mode "InitializationVector" Automatic initialization vector for block ciphers "BlockMode" "CBC" block chaining mode ("ECB","CBC", "OFB", "CFB", "CTR") - The "Padding" element in the association assoc specifies the padding method to pad incomplete input.
- Encryption with symmetric key supports the following padding methods: Automatic and None.
- Encryption with a public key and decryption with a private key support the following padding methods: "PKCS1", "OAEP", None.
- Encryption with a private key and decryption with a public key support the following padding methods: "PKCS1", None.
- The "PKCS1" padding method is used as a default for asymmetric encryption.
- All ciphers except RC4 and RSA can use the block modes "ECB", "CBC", "CFB", "OFB". "RC4" can only use None.
- Possible settings for "InitializationVector" include:
-
Automatic generate an appropriate initialization vector ByteArray[…] use an explicitly specified initialization vector - With "InitializationVector"->Automatic, Encrypt will generate a new initialization vector whenever it is run. Later, the vector can be obtained from the EncryptedObject that was produced.
- Supported ciphers, together with default initialization vector size, include:
-
"Blowfish" 64 bits "CAST5" 64 bits "DES" 64 bits "IDEA" 64 bits "AES128" 128 bits "AES192" 128 bits "AES256" 128 bits - For RSA cipher, 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" < "OAEP" < None
Examples
open allclose allBasic Examples (3)Summary of the most common use cases
Encrypt a message with a password:

https://wolfram.com/xid/05fltzmt9i-n1waj4

Show the raw encrypted data and details about the encryption algorithm used:

https://wolfram.com/xid/05fltzmt9i-7v417e

Decrypt with the password to get back the message:

https://wolfram.com/xid/05fltzmt9i-pvra37


https://wolfram.com/xid/05fltzmt9i-kzg01t


https://wolfram.com/xid/05fltzmt9i-n1tl7l


https://wolfram.com/xid/05fltzmt9i-5xriaw

Generate public and private keys:

https://wolfram.com/xid/05fltzmt9i-cwxm9r


https://wolfram.com/xid/05fltzmt9i-ipnt9s

Decrypt using the private key:

https://wolfram.com/xid/05fltzmt9i-pqhpfb

Alternatively, encrypt using the private key:

https://wolfram.com/xid/05fltzmt9i-sgnkj4

Now decrypt using the public key:

https://wolfram.com/xid/05fltzmt9i-1kevv2

Scope (2)Survey of the scope of standard use cases

https://wolfram.com/xid/05fltzmt9i-rrb3jz


https://wolfram.com/xid/05fltzmt9i-jicptj

Byte arrays are encrypted literally, making them more easily usable with external programs:

https://wolfram.com/xid/05fltzmt9i-818qo9


https://wolfram.com/xid/05fltzmt9i-7dfoeb

Options (5)Common values & functionality for each option
Method (5)
Encrypt using a specific initialization vector:

https://wolfram.com/xid/05fltzmt9i-pxqq91

With the initialization vector set to Automatic, a random initialization vector will be generated every time Encrypt is called:

https://wolfram.com/xid/05fltzmt9i-7ywgfa


https://wolfram.com/xid/05fltzmt9i-bvwcpe


https://wolfram.com/xid/05fltzmt9i-usw87u

Specify a padding scheme to use for RSA encryption:

https://wolfram.com/xid/05fltzmt9i-ed2w65

Encrypt exactly one block of data by setting "Padding" to None:

https://wolfram.com/xid/05fltzmt9i-dfqlcp

Applications (2)Sample problems that can be solved with this function
Encrypt a message and save the ciphertext to a file:

https://wolfram.com/xid/05fltzmt9i-mbspwp


https://wolfram.com/xid/05fltzmt9i-kiomi0

https://wolfram.com/xid/05fltzmt9i-zbezu6
Read back the contents of the file as bytes:

https://wolfram.com/xid/05fltzmt9i-094wt4

Compare with the original ciphertext:

https://wolfram.com/xid/05fltzmt9i-nkigts


https://wolfram.com/xid/05fltzmt9i-1k082
Write simple cryptographic signing and verification functions:

https://wolfram.com/xid/05fltzmt9i-isk1hv

https://wolfram.com/xid/05fltzmt9i-65xzmd
Generate a pair of public and private keys:

https://wolfram.com/xid/05fltzmt9i-qbo127


https://wolfram.com/xid/05fltzmt9i-7fxog


https://wolfram.com/xid/05fltzmt9i-thz5mt

Verify that the signature is authentic:

https://wolfram.com/xid/05fltzmt9i-d3elvz

Verifying with another expression will fail:

https://wolfram.com/xid/05fltzmt9i-pk0bzd

Properties & Relations (2)Properties of the function, and connections to other functions
The returned encrypted object stores all aspects of the encrypted result:

https://wolfram.com/xid/05fltzmt9i-9bf60r

Extract the bytes in the ciphertext:

https://wolfram.com/xid/05fltzmt9i-l06h5e

Extract the bytes in the initialization vector used for encryption:

https://wolfram.com/xid/05fltzmt9i-17ubsw

Some block modes are more secure than others:

https://wolfram.com/xid/05fltzmt9i-qc6wid
There is a noticeable repeating pattern when encrypting uniform data using ECB:

https://wolfram.com/xid/05fltzmt9i-g6geb

https://wolfram.com/xid/05fltzmt9i-0fqu7e


https://wolfram.com/xid/05fltzmt9i-cytm2q

https://wolfram.com/xid/05fltzmt9i-uxn82k

Possible Issues (5)Common pitfalls and unexpected behavior
Timing (1)
Encrypting using a password requires key derivation, which is intentionally slow:

https://wolfram.com/xid/05fltzmt9i-e4oaym

You can avoid this by pre-generating a key:

https://wolfram.com/xid/05fltzmt9i-v37hzh


https://wolfram.com/xid/05fltzmt9i-0yq5w1

Encrypted Data Size (1)
Incompatible Keys (1)
Incompatible Padding Modes (1)
Incompatible Block Modes (1)
RSA is an asymmetric cipher that does not support block modes of operation, so Encrypt will proceed ignoring the setting for "BlockMode":

https://wolfram.com/xid/05fltzmt9i-nuwzgx


RC4 is a stream that does not support block modes of operation, so Encrypt will proceed ignoring the setting for "BlockMode":

https://wolfram.com/xid/05fltzmt9i-s6a3bk


Wolfram Research (2015), Encrypt, Wolfram Language function, https://reference.wolfram.com/language/ref/Encrypt.html (updated 2023).
Text
Wolfram Research (2015), Encrypt, Wolfram Language function, https://reference.wolfram.com/language/ref/Encrypt.html (updated 2023).
Wolfram Research (2015), Encrypt, Wolfram Language function, https://reference.wolfram.com/language/ref/Encrypt.html (updated 2023).
CMS
Wolfram Language. 2015. "Encrypt." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2023. https://reference.wolfram.com/language/ref/Encrypt.html.
Wolfram Language. 2015. "Encrypt." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2023. https://reference.wolfram.com/language/ref/Encrypt.html.
APA
Wolfram Language. (2015). Encrypt. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Encrypt.html
Wolfram Language. (2015). Encrypt. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Encrypt.html
BibTeX
@misc{reference.wolfram_2025_encrypt, author="Wolfram Research", title="{Encrypt}", year="2023", howpublished="\url{https://reference.wolfram.com/language/ref/Encrypt.html}", note=[Accessed: 19-June-2025
]}
BibLaTeX
@online{reference.wolfram_2025_encrypt, organization={Wolfram Research}, title={Encrypt}, year={2023}, url={https://reference.wolfram.com/language/ref/Encrypt.html}, note=[Accessed: 19-June-2025
]}