Created
November 13, 2014 20:44
-
-
Save PartTimeLegend/4168957d041003508acc to your computer and use it in GitHub Desktop.
Encrypt Files C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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