How to Decrypt a File in C#

C# provides functionality to encrypt files. The File class provides the Encrypt and the Decrypt methods. The following code examples show how to use Encrypt and Decrypt methods.

Only an encrypted file can be decrypted. The File.Decrypt method decrypts a file that has been encrypted previously by the same user. 

The following code example encrypts a file using the File.Ecrypt method:

string fileName = @"c:\temp\Mahesh.txt";
File.Encrypt(fileName);

Now, the File.Decrypt method decrypts the encrypted file. Only an account that has encrypted a file can decrypt a file.

string fileName = @"c:\temp\Mahesh.txt";
File.Decrypt(fileName);

Learn more about the File class here: Working With File Class In C# (c-sharpcorner.com).


Similar Articles