How to Encrypt a File in C#?

The File class provides the Encrypt and the Decrypt methods to restrict other users from reading a file without decrypting an encrypted file.  

Encrypt a File in C#

The Encrypt method encrypts a file so that only the account used to encrypt the file can decrypt it.

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

Decrypt a File in C#

The Decrypt method decrypts an encrypted file. Only an account that has encrypted a file can decrypt it.

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

Here are more details about the File class and its methods: Working With File Class In C# (c-sharpcorner.com).


Similar Articles