private void EncryptFile( string sourceFile, string targetFile, string key)
{
AesManage aes = new AesManage();
using ( MD5CryptoServiProvider md5 = new MD5CryptoServiProvider()){
AES.KeySize = md5.HashSize;
AES.BlockSize = md5.HashSize();
AES.IV = md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes("stick some string in here"));
AES.Key = md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(key));
}
using(FileStream reader = new FileStream(sourceFile, FileMode.Open, FileAcess.Read) )
{
using(FileStream writer = new FileStream(sourceFile, FileMode.OpenOrCreate, FileAcess.Write){
using(CryptoStream cs = new CryptoStream(writer, AES.CreateEncryptor(), CryptoStreamMode.Write){
int bufferSize = 4096;
byte[] buffer = new byte[bufferSize];
int bytesRead;
do
{
bytesRead = reader.Read(buffer, 0, bufferSize);
if(bytesRead != 0)
{
cs.Write(buffer, 0, bytesRead);
}
}
while(bytesRead != 0);
cs.FlushFinalBlock();
}
}
}
}