private void TDES_EncryptFile() { Stream myStream; SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "Encrypted File (*.enc)|*.enc"; saveFileDialog1.RestoreDirectory = true; if (saveFileDialog1.ShowDialog() == true) { if ((myStream = saveFileDialog1.OpenFile()) != null) myStream.Close(); string keyText = keys2.Text; byte[] keyBytes = ASCIIEncoding.ASCII.GetBytes(keyText); byte[] ivBytes = ASCIIEncoding.ASCII.GetBytes(keyText); string inputFile = Openfile.Text; string encryptedFile = saveFileDialog1.FileName; using (FileStream inputFileStream = File.Open(inputFile, FileMode.Open)) using (FileStream outputFileStream = File.Open(encryptedFile, FileMode.Create)) { using (TripleDESCryptoServiceProvider tds = new TripleDESCryptoServiceProvider()) { tds.Key = keyBytes; tds.IV = ivBytes; ICryptoTransform cryptoTransform = tds.CreateEncryptor(); using (CryptoStream cryptoStream = new CryptoStream(outputFileStream, cryptoTransform, CryptoStreamMode.Write)) { byte[] buffer = new byte[inputFileStream.Length]; inputFileStream.Read(buffer, 0, buffer.Length); cryptoStream.Write(buffer, 0, buffer.Length); MessageBox.Show("The File Was Successfully Encrypted", "Encrypted!", MessageBoxButton.OK, MessageBoxImage.Information); } } } } }
byte[] keyBytes = md5.ComputeHash(utf.GetBytes(keyText)); byte[] ivBytes = ASCIIEncoding.ASCII.GetBytes(keyText.Substring(0, 8));
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)