File encryption using c#.net
try
{
string InputFile = Application.StartupPath
+ "\\softtechsolving.xls"; // this is excel
file, i.e I wanna to encrypt
string
OutputFile = = Application.StartupPath + "\\encrptsofttechsolving.xml"; // encrptsofttechsolving
is file name after encryption file name saved
that name
string
password = @"xxxxx"; // Your Key Here
UnicodeEncoding
UE = new UnicodeEncoding();
byte[]
key = UE.GetBytes(password);
FileStream
fsCrypt = new FileStream(outputFile,
FileMode.Create);
RijndaelManaged
RMCrypto = new RijndaelManaged();
CryptoStream
cs = new CryptoStream(fsCrypt,
RMCrypto.CreateEncryptor(key, key),
CryptoStreamMode.Write);
FileStream
fsIn = new FileStream(inputFile,
FileMode.Open);
int
data;
while
((data = fsIn.ReadByte()) != -1)
cs.WriteByte((byte)data);
fsIn.Close();
cs.Close();
fsCrypt.Close();
MessageBox.Show("Backup Done", "Demo
Software");
}
catch
{
MessageBox.Show("Encryption failed!", "Error");
}
Namespace:
Adding
using
System.Xml;
using System.IO;
using
System.Security.Cryptography;
using
System.Xml.Linq;
using
System.Xml.Serialization;
using
System.Data.SqlClient;