Skip to content

Instantly share code, notes, and snippets.

@PartTimeLegend
Created November 13, 2014 20:44
Show Gist options
  • Save PartTimeLegend/4168957d041003508acc to your computer and use it in GitHub Desktop.
Save PartTimeLegend/4168957d041003508acc to your computer and use it in GitHub Desktop.
Encrypt Files C#
public void EncrpytFiles(IList<Documents> documentsList)
{
foreach (var document in documentsList)
{
TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
tdes.Padding = (PaddingMode.ISO10126);
tdes.Mode = CipherMode.CBC;
tdes.GenerateIV();
tdes.GenerateKey();
tdes.CreateEncryptor();
FileStream fStream = File.Open(document.ToString(), FileMode.OpenOrCreate);
CryptoStream cStream = new CryptoStream(fStream,
new TripleDESCryptoServiceProvider().CreateEncryptor(tdes.Key, tdes.Key),
CryptoStreamMode.Write);
StreamWriter sWriter = new StreamWriter(cStream);
sWriter.WriteLine(fStream);
sWriter.Close();
cStream.Close();
fStream.Close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment