Encrypt and Decrypt a file in CSharp

Description

The following code shows how to encrypt and Decrypt a file.

Example


  //from w ww . j  a va  2 s .c  o  m
  
  
   
using System;
using System.IO;
using System.Security.AccessControl;

class FileExample
{
        public static void Main()
        {
                string FileName = "test.xml";
                AddEncryption(FileName);
                Console.WriteLine("Decrypt " + FileName);
                RemoveEncryption(FileName);
        }
        public static void AddEncryption(string FileName)
        {
            File.Encrypt(FileName);
        }
        public static void RemoveEncryption(string FileName)
        {
            File.Decrypt(FileName);
        }
}




















Home »
  C# Tutorial »
    IO »




File Attribute
File Security
Directory Attribute
Directory Recursive
Binary File
Text Field
Buffered IO
Create Copy Delete Move
CSV
Drive
File System Watcher
Isolated Storage
MemoryStream
Serialize
Zip