Exemplo n.º 1
0
        private void Button3DESDecrypt_Click(object sender, RoutedEventArgs e)
        {
            fileBytes = System.IO.File.ReadAllBytes(fileName);
            byte[] key       = Encoding.Unicode.GetBytes(textbox3DESKey.Text);
            byte[] decrypted = TripleDESx.Decrypt(fileBytes, tripleKey);

            SaveFileDialog dlg = new SaveFileDialog();

            dlg.FileName = "DecryptedFile";

            Nullable <bool> result = dlg.ShowDialog();

            if (result == true)
            {
                // Save document
                string filename = dlg.FileName + fileExtension;
                File.WriteAllBytes(filename, decrypted);
            }
        }
Exemplo n.º 2
0
        private void Button3DESEncrypt_Click(object sender, RoutedEventArgs e)
        {
            fileBytes = System.IO.File.ReadAllBytes(fileName);
            Dictionary <string, byte[]> encrypted = TripleDESx.Encrypt(fileBytes);

            byte[] encryptedBytes = encrypted["text"];
            textbox3DESKey.Text = Encoding.Unicode.GetString(encrypted["key"]);
            tripleKey           = encrypted["key"];

            SaveFileDialog dlg = new SaveFileDialog();

            dlg.FileName = "EncryptedFile";
            dlg.Filter   = "File (All) |*" + fileExtension;

            Nullable <bool> result = dlg.ShowDialog();

            if (result == true)
            {
                // Save document
                string filename = dlg.FileName;
                File.WriteAllBytes(filename, encryptedBytes);
            }
        }