File decryption using c#.net

c# code:          

  string InputFile = Application.StartupPath +"\\ encrptsofttechsolving.xml ";   // this is excel file, i.e I  wanna to deencrypt
                string OutputFile = = Application.StartupPath +"\\softtechsolving.xls ";   // softtechsolving is file name after decryption of  encrptsofttechsolving.xml
            XmlDocument XDoc1 = new XmlDocument();
            try
            {
                string password = @"xxxxxxx"; // Your Key Here

                UnicodeEncoding UE = new UnicodeEncoding();
                byte[] key = UE.GetBytes(password);

                FileStream fsCrypt = new FileStream(inputFile, FileMode.Open);

                RijndaelManaged RMCrypto = new RijndaelManaged();

                CryptoStream cs = new CryptoStream(fsCrypt,
                    RMCrypto.CreateDecryptor(key, key),
                    CryptoStreamMode.Read);

                FileStream fsOut = new FileStream(outputFile, FileMode.Create);

                int data;
                while ((data = cs.ReadByte()) != -1)
                    fsOut.WriteByte((byte)data);

                fsOut.Close();
                cs.Close();
                fsCrypt.Close();

            }
            catch (Exception ex)
            {
                //MessageBox.Show("DecryptFile failed!", "Error");
            }Namespace:
Adding
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Security.Cryptography;

using System.Xml;

Popular posts from this blog

How to create bootable pendrive using DOS