Decrypt
Details
- Decrypt[…,enc] takes an EncryptedObject[…] generated by Encrypt.
- In a notebook interface, Decrypt[expr] generates a dialog box; in a textual interface it generates a textual prompt.
- For a symmetric encryption method, Decrypt[key,Encrypt[key,expr]] gives expr.
- Decrypt returns an expression in the form specified by EncryptedObject[…]["OriginalForm"].
Examples
open all close allBasic Examples (3)
Encrypt a message with a password:
Encrypt["my password", "Now is the time..."]Decrypt with the same password to get back the message:
Decrypt["my password", %]key = GenerateSymmetricKey[]Encrypt[key, "Now is the time..."]Decrypt[key, %]Generate public and private keys:
keys = GenerateAsymmetricKeyPair[]Encrypt[keys["PublicKey"], "Now is the time..."]Decrypt using the private key:
Decrypt[keys["PrivateKey"], %]Alternatively, encrypt using the private key:
Encrypt[keys["PrivateKey"], "Now is the time..."]Now decrypt using the public key:
Decrypt[keys["PublicKey"], %]Scope (3)
Encrypt["my password", Graphics[Disk[]]]Decrypt to get back the exact expression:
Decrypt["my password", %]To decrypt byte array encrypted data, Decrypt needs to know details of the encryption algorithm used:
data = ByteArray["HyEEIAp4iTI8Fv2BJpqjqDjwZU9jfKii3p0YqMsSJwvTzT1t+wthV7ODqjLfL6/nkUOuWVeQr7Tp1RBjZb1KO/Zc\
gg7YzoakSz/wy+jlh3bVpmem3V77AW9dcg1wHUzcnZzPR4Yl5fYbrDHdg5HnpmppN4B9eVrPa4OIV4PimdpkvN7abdDhfHDNzxR\
YET2M2MzmobaPD29NaY/trvgDJI7qK+52A4sTHiiDEtGhiyPImZgsF/pjiZDUYAMnU7lDfzsORRAn4HahEKwIPG22K5NwgdbB2o\
gGDNUTxy4ZEYildjSd5cwddWN/yh2KlHcyzv40RoppN0xKIEHWCAeI8A=="];Create an EncryptedObject to specify the cipher, padding mode and format of the plaintext message:
encrypted = EncryptedObject[<|"Cipher" -> "RSA", "Data" -> data, "OriginalForm" -> String, "Padding" -> Automatic|>]Decrypt using the correct password or key:
Decrypt[PrivateKey[Association["Type" -> "RSA", "Cipher" -> "RSA", "Padding" -> "PKCS1",
"PublicExponent" -> 65537, "PublicModulus" -> 222999274349291996838327545482429681975946235960406\
29785429933350406512922509037007038753702646027203641330283959977 ... zKsiI+P2eRwpy+s0p9th7mdTuu/pD/U+UhwFu32W1YyLn6ZLb1UFQ+dCms\
f9tbGgpfD6Hx+mWv1FPzENeJCLNwMGHvK3iJuMuASAiaR7UDz1X6qrp+T5j1LxDcGsJVANKVRxcGAgNt3QGKIvPyjE7Jxhxu98g\
Sm7aze3mDZGZCf1ofYAUuG2imZZPFsA/aIE/buyANKuJ+zleh/OvoyRLG0y+QVrL6EjeX3fcoLRywxgQ=="]]], encrypted]Symmetric ciphers usually require an initialization vector for decryption:
data = ByteArray["Jw71WcKfKyJ5STiCH1a+Qd3sworv5j7IINTEJXKfEWQ="];
iv = ByteArray["r922W/6m/KASJatnG9tnpg=="];Create an EncryptedObject to specify the cipher, block mode, initialization vector and format of the plaintext message:
encrypted = EncryptedObject[<|"Cipher" -> "AES256", "BlockMode" -> "CBC", "Data" -> data, "InitializationVector" -> iv, "OriginalForm" -> String|>]Decrypt using the correct password or key:
Decrypt["my password", encrypted]Applications (1)
Write simple cryptographic signing and verification functions:
sign[key_PrivateKey, expr_] := Encrypt[key, Hash[expr, "SHA256"]]verify[key_PublicKey, expr_, signature_EncryptedObject] := Decrypt[key, signature] === Hash[expr, "SHA256"]Generate a pair of public and private keys:
keys = GenerateAsymmetricKeyPair[]expr = Graphics[Disk[]]sig = sign[keys["PrivateKey"], expr]Verify that the signature is authentic:
verify[keys["PublicKey"], expr, sig]Verifying with another expression will fail:
verify[keys["PublicKey"], "another expression", sig]Related Guides
Text
Wolfram Research (2015), Decrypt, Wolfram Language function, https://reference.wolfram.com/language/ref/Decrypt.html (updated 2019).
CMS
Wolfram Language. 2015. "Decrypt." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2019. https://reference.wolfram.com/language/ref/Decrypt.html.
APA
Wolfram Language. (2015). Decrypt. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Decrypt.html
BibTeX
@misc{reference.wolfram_2026_decrypt, author="Wolfram Research", title="{Decrypt}", year="2019", howpublished="\url{https://reference.wolfram.com/language/ref/Decrypt.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_decrypt, organization={Wolfram Research}, title={Decrypt}, year={2019}, url={https://reference.wolfram.com/language/ref/Decrypt.html}, note=[Accessed: 12-June-2026]}