private void btnInputFileDecrypt_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                OpenFileDialog chooseFileToDecryptFromDialog = new OpenFileDialog();
                chooseFileToDecryptFromDialog.Title            = "Wybór pliku do odszyfrowania";
                chooseFileToDecryptFromDialog.InitialDirectory = @"C:\";
                chooseFileToDecryptFromDialog.CheckFileExists  = true;
                chooseFileToDecryptFromDialog.CheckPathExists  = true;

                if (chooseFileToDecryptFromDialog.ShowDialog() == DialogResult.OK)
                {
                    textBoxDecryptInputFile.Text = chooseFileToDecryptFromDialog.FileName;
                    inputFileDecryptPath         = textBoxDecryptInputFile.Text;
                }

                if (inputFileDecryptPath != null)
                {
                    inStr = File.OpenRead(inputFileDecryptPath);

                    //odczytanie naglowka
                    using (var ms = new MemoryStream())
                    {
                        byte[] buff = new byte[1];
                        while (true)
                        {
                            inStr.Read(buff, 0, 1);

                            if (buff[0] == (byte)3)
                            {
                                break;
                            }

                            ms.Write(buff, 0, 1);
                        }

                        ms.Position = 0;
                        XmlSerializer ser = new XmlSerializer(typeof(XmlMetadata));
                        metadataDecrypt = (XmlMetadata)ser.Deserialize(ms);
                    }

                    ComboBoxRecipient.ItemsSource = metadataDecrypt.Recipients;
                }
            }
            catch
            {
                textBoxDecryptInputFile.Text = "";
                // errorMsg = "niepoprawny plik";
            }
        }
Example #2
0
        public static byte[] GenerateXmlHeader(List <Recipient> recipients, string keySize, string cipherMode, string iv)
        {
            XmlMetadata metadata = new XmlMetadata()
            {
                Algorithm  = "AES",
                CipherMode = cipherMode,
                IV         = iv,
                KeySize    = keySize,
                Recipients = recipients
            };

            byte[]        result;
            XmlSerializer serializer = new XmlSerializer(typeof(XmlMetadata));

            using (var ms = new MemoryStream())
            {
                serializer.Serialize(ms, metadata);
                result = ms.ToArray();
            }
            return(result);
        }