({{, (RefLink[DecryptFile, paclet:ref/DecryptFile])["password",file] 
generates a decrypted version of a file, using the specified password.}, {, (RefLink[DecryptFile, paclet:ref/DecryptFile])["password",source,target]
generates a decrypted version of source, putting the result in target.}, {, (RefLink[DecryptFile, paclet:ref/DecryptFile])[keyspec,source,…]
decrypts using the cryptographic key specification keyspec.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[DecryptFile, paclet:ref/DecryptFile]) takes a file encrypted by (RefLink[EncryptFile, paclet:ref/EncryptFile]).

(RefLink[DecryptFile, paclet:ref/DecryptFile]) works with both files and cloud objects.

(RefLink[DecryptFile, paclet:ref/DecryptFile])[key,file] returns the name of the decrypted version of file, or (RefLink[$Failed, paclet:ref/$Failed]) if the file could not be decrypted with key.

(RefLink[DecryptFile, paclet:ref/DecryptFile])[key,(RefLink[CloudObject, paclet:ref/CloudObject])[…]] returns a new anonymous cloud object containing the decrypted version of the contents of the original cloud object, or (RefLink[$Failed, paclet:ref/$Failed]) if the original cloud object could not be decrypted with key.

The cryptographic key specification keyspec for (RefLink[DecryptFile, paclet:ref/DecryptFile])[keyspec,…] has the same form as for (RefLink[Decrypt, paclet:ref/Decrypt]).

(RefLink[DecryptFile, paclet:ref/DecryptFile]) has the following options:

The setting for (RefLink[Permissions, paclet:ref/Permissions]) affects only cloud objects newly created by (RefLink[DecryptFile, paclet:ref/DecryptFile])[key,(RefLink[CloudObject, paclet:ref/CloudObject])[…]], not cloud objects explicitly specified as targets.

With (RefLink[Permissions, paclet:ref/Permissions])->(RefLink[Automatic, paclet:ref/Automatic]), any permissions set will be given by (RefLink[$Permissions, paclet:ref/$Permissions]). However, if (RefLink[$Permissions, paclet:ref/$Permissions]) is not "Private", (RefLink[DecryptFile, paclet:ref/DecryptFile]) will give a message when it generates a cloud object.

The setting for (RefLink[OverwriteTarget, paclet:ref/OverwriteTarget]) affects only files to be newly created by (RefLink[DecryptFile, paclet:ref/DecryptFile])[key,file] whose names would collide with existing files.

OpenersPrimaryExamplesSection(Spacer1)Examples  (10)

OpenersExampleSection0(Spacer1)Basic Examples  (4)

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

Delete the original file:

DeleteFile["tmp.txt"]

Decrypt the encrypted file:

DecryptFile["my password","tmp.txt.mx"]

Read the decrypted file:

ReadString["tmp.txt"]

Delete the files used in this example:

DeleteFile[{"tmp.txt","tmp.txt.mx"}]

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 the decrypted file:

Import["rose.gif"]

Delete the files used in this example:

DeleteFile[{"codedrose.mx","rose.gif"}]

Create a cloud object:

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 file decrypted cloud object:

CloudGet[%]

Create an archive file from a directory:

CreateArchive[$InstallationDirectory<>"/Documentation/English/System/ExampleData/","example.zip"]

Encrypt the archive file:

EncryptFile["my password",%]

Delete the original archive:

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"}]

OpenersExampleSection1(Spacer1)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 the file:

Import[%]

DeleteFile["newrose.gif"]

Generate a key:

key=GenerateSymmetricKey[]

Encrypt using the key:

EncryptFile[key,FindFile["ExampleData/rose.gif"],"rose.gif.mx"]

Decrypt using the same key:

DecryptFile[key,%]

DeleteFile[{"rose.gif","rose.gif.mx"}]

OpenersExampleSection2(Spacer1)Options  (2)

OpenersExampleSubsection0(Spacer1)Permissions  (1)

Create a cloud object:

CloudPut["Now is the time..."]

Encrypt the cloud object:

EncryptFile["my password",%]

Decrypt the cloud object, creating a new cloud object and setting its permissions to public:

DecryptFile["my password",%,Permissions->"Public"]

The decrypted cloud object is now publicly readable:

Options[%,Permissions]

OpenersExampleSubsection1(Spacer1)OverwriteTarget  (1)

Write a string to the file tmp.txt:

WriteString["tmp.txt","Now is the time..."]

Encrypt the file:

EncryptFile["my password","tmp.txt"]

This attempts to write over tmp.txt:

DecryptFile["my paswword","tmp.txt.mx"]

With (RefLink[OverwriteTarget, paclet:ref/OverwriteTarget])->(RefLink[True, paclet:ref/True]), (RefLink[DecryptFile, paclet:ref/DecryptFile]) overwrites tmp.txt:

DecryptFile["my password","tmp.txt.mx",OverwriteTarget->True]

DeleteFile[{"tmp.txt","tmp.txt.mx"}]

OpenersExampleSection3(Spacer1)Possible Issues  (2)

Write a string to a file:

WriteString["tmp.txt","Now is the time..."]

Encrypt the file using the password "my password":

EncryptFile["my password","tmp.txt"]

Delete the original file:

DeleteFile["tmp.txt"]

If you use the wrong password, you get a message:

DecryptFile["not my password","tmp.txt.mx"]

DeleteFile["tmp.txt.mx"]

Create a cloud object:

CloudPut["Now is the time..."]

Encrypt the cloud object, getting back another cloud object:

EncryptFile["my password",%]

If (RefLink[$Permissions, paclet:ref/$Permissions]) is not "Private", (RefLink[DecryptFile, paclet:ref/DecryptFile]) gives a message:

Block[{$Permissions="Public"},DecryptFile["my password",%]]

If the (RefLink[Permissions, paclet:ref/Permissions]) option is explicitly set, no message is issued:

Block[{$Permissions="Public"},DecryptFile["my password",%%,Permissions->"Public"]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[EncryptFile, paclet:ref/EncryptFile])  ▪  (RefLink[Decrypt, paclet:ref/Decrypt])  ▪  (RefLink[SymmetricKey, paclet:ref/SymmetricKey])  ▪  (RefLink[GenerateSymmetricKey, paclet:ref/GenerateSymmetricKey])  ▪  (RefLink[GenerateAsymmetricKeyPair, paclet:ref/GenerateAsymmetricKeyPair])  ▪  (RefLink[AuthenticationDialog, paclet:ref/AuthenticationDialog])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Cryptography, paclet:guide/Cryptography])}, {▪(RefLinkPlain[File Operations, paclet:guide/FileOperations])}})}})