EncryptFile["password",file]
generates an encrypted version of a file, using the specified password.
EncryptFile["password",source,target]
generates an encrypted version of source, putting the result in target.
EncryptFile[keyspec,source,…]
encrypts using the cryptographic key specification keyspec.
EncryptFile
EncryptFile["password",file]
generates an encrypted version of a file, using the specified password.
EncryptFile["password",source,target]
generates an encrypted version of source, putting the result in target.
EncryptFile[keyspec,source,…]
encrypts using the cryptographic key specification keyspec.
Details and Options
- EncryptFile generates an encrypted file, suitable for decryption with DecryptFile.
- EncryptFile works with both files and cloud objects.
- EncryptFile[key,file] returns the name of the encrypted version of file.
- EncryptFile[key,CloudObject[…]] returns a new anonymous cloud object containing the encrypted version of the contents of the original cloud object.
- EncryptFile[key,File[…]] is also supported.
- The cryptographic key specification keyspec for EncryptFile[keyspec,…] has the same form as for Encrypt.
- EncryptFile has the following options:
-
Permissions Automatic permissions to set for created cloud objects OverwriteTarget False whether to overwrite an existing file with an automatically named new file Method Automatic details of encryption method - EncryptFile uses the same Method option specifications as Encrypt.
- The setting for Permissions affects only cloud objects newly created by EncryptFile[key,CloudObject[…]], not cloud objects explicitly specified as targets.
- With Permissions->Automatic, any permissions set will be given by $Permissions.
- The setting for OverwriteTarget affects only files to be newly created by EncryptFile[key,file] whose names would collide with existing files.
Examples
open all close allBasic Examples (4)
origfile = CreateFile[];
WriteString[origfile, "Now is the time..."]
Close[origfile];Encrypt the file using a password:
encfile = EncryptFile["my password", origfile];DeleteFile[origfile]DecryptFile["my password", encfile, origfile];ReadString[origfile]Delete the files used in this example:
DeleteFile[{origfile, encfile}]Encrypt a file containing an image, putting the result in a new file:
EncryptFile["my password", FindFile["ExampleData/rose.gif"], "codedrose.mx"]Decrypt the encrypted file, again putting the result in a new file:
DecryptFile["my password", "codedrose.mx", "rose.gif"]Import["rose.gif"]Delete the files used in this example:
DeleteFile[{"codedrose.mx", "rose.gif"}]CloudPut["Now is the time..."]Encrypt the cloud object, getting back another cloud object:
EncryptFile["my password", %]Decrypt the encrypted cloud object, getting back yet another cloud object:
DecryptFile["my password", %]Get the contents of the decrypted cloud object:
CloudGet[%]Create an archive file from a directory:
CreateArchive[$InstallationDirectory <> "/Documentation/English/System/ExampleData/", "example.zip"]EncryptFile["my password", %]DeleteFile["example.zip"]Decrypt the encrypted archive:
DecryptFile["my password", "example.zip.mx"]Extract the archive into the current directory:
ExtractArchive["example.zip"];Delete the extracted directory and intermediate files used in this example:
DeleteDirectory["ExampleData", DeleteContents -> True]DeleteFile[{"example.zip", "example.zip.mx"}]Scope (2)
Encrypt a file and put the result in a cloud object:
EncryptFile["my password", FindFile["ExampleData/rose.gif"], CloudObject[]]Decrypt the cloud object and put the result into a local file:
DecryptFile["my password", %, "newrose.gif"]Import[%]DeleteFile["newrose.gif"]key = GenerateSymmetricKey[]EncryptFile[key, FindFile["ExampleData/rose.gif"], "rose.gif.mx"]DecryptFile[key, %]DeleteFile[{"rose.gif", "rose.gif.mx"}]Options (2)
Permissions (1)
CloudPut["Now is the time..."]Encrypt the cloud object, setting the permissions of the resulting cloud object to public:
EncryptFile["my password", %, Permissions -> "Public"]The encrypted cloud object is now publicly readable:
Options[%, Permissions]OverwriteTarget (1)
Write a string to the file tmp.txt:
WriteString["tmp.txt", "Now is the time..."]Close["tmp.txt"]Encrypt the file, getting back the tmp.txt.mx:
EncryptFile["my password", "tmp.txt"]This attempts to write over tmp.txt.mx:
EncryptFile["my password", "tmp.txt"]With OverwriteTarget->True, EncryptFile overwrites tmp.txt.mx:
EncryptFile["my password", "tmp.txt", OverwriteTarget -> True]DeleteFile[{"tmp.txt", "tmp.txt.mx"}]Properties & Relations (2)
Write a string to the file tmp.txt:
WriteString["tmp.txt", "Now is the time..."]Encrypt the file tmp.txt using a password:
EncryptFile["my password", "tmp.txt"]Importing the file written by EncryptFile gives an EncryptedObject:
Import[%]DeleteFile[{"tmp.txt", "tmp.txt.mx"}]Write a string to the file tmp.txt:
WriteString["tmp.txt", Range[1000]]EncryptFile["my password", "tmp.txt" ]The original and encrypted files are about the same size:
{FileByteCount["tmp.txt"], FileByteCount["tmp.txt.mx"]}DeleteFile[{"tmp.txt", "tmp.txt.mx"}]Related Guides
Text
Wolfram Research (2017), EncryptFile, Wolfram Language function, https://reference.wolfram.com/language/ref/EncryptFile.html (updated 2020).
CMS
Wolfram Language. 2017. "EncryptFile." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/EncryptFile.html.
APA
Wolfram Language. (2017). EncryptFile. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/EncryptFile.html
BibTeX
@misc{reference.wolfram_2026_encryptfile, author="Wolfram Research", title="{EncryptFile}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/EncryptFile.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_encryptfile, organization={Wolfram Research}, title={EncryptFile}, year={2020}, url={https://reference.wolfram.com/language/ref/EncryptFile.html}, note=[Accessed: 13-June-2026]}