Code to encrypt and decrypt files using C#.Net, ASP.Net

By
Advertisement
In this article i am going to explain about how to encrypt and decrypt files using C#.Net, ASP.Net.


The Microsoft Windows operating system's NTFS file system includes the facility to encrypt files to reduce the risk that their contents are seen by unauthorised people.

Steps to follow:

1. Add the following using directive to your code:


using System.IO;


2. To encrypt a file, call the Encrypt method. 

This has a single parameter, which is used to specify the path of the file to be encrypted. You can also specify the path to a folder, in which case all new files added to the folder will be encrypted automatically.

Syntax:


File.Encrypt(@"Path of the file or folder");


This method accepts single parameter, which is used to specify the path of the file to be encrypted. 

You can also specify the path to a folder, in which case all new files added to the folder will be encrypted automatically.

Example:


File.Encrypt(@"C:\myFolder\myFile.txt");


3. To remove encryption from a file or folder programmatically, you can use the Decrypt method

Syntax:


File.Decrypt(@"Path of the file or folder");


Example:


File.Decrypt(@"C:\myFolder\myFile.txt");

2 comments:

  1. this is the most worst demostration of encrytion. I request to aurthor please remove it.

    ReplyDelete
    Replies
    1. Thanks for your comment. Can u suggest some good article link to refer?

      Delete

Online Casino