encrypts expr using the specified password, to give an encrypted object.
encrypts expr using the cryptographic key specification keyspec.
interactively requests a password with which to encrypt expr.
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
Examplesopen allclose all
Basic Examples (3)
Encrypt exactly one block of data by setting "Padding" to None:
Properties & Relations (2)
Possible Issues (5)
Incompatible Padding Modes (1)
Wolfram Research (2015), Encrypt, Wolfram Language function, https://reference.wolfram.com/language/ref/Encrypt.html (updated 2023).
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. Retrieved from https://reference.wolfram.com/language/ref/Encrypt.html