Ejemplo n.º 1
0
        private void decryptButton_Click(object sender, EventArgs e)
        {
            try
            {
                AudioEncoder decoder = new AudioEncoder();

                if (string.IsNullOrEmpty(encryptedAudioPathTextBox.Text))
                {
                    throw new Exception("Encrypted audio file was not selected");
                }

                decoder.WavToBytes(encryptedAudioPathTextBox.Text);

                byte[] message = decoder.RemoveMessage();

                if (string.IsNullOrEmpty(encryptionKeyTextBox.Text))
                {
                    throw new Exception("Generation key was not provided");
                }

                string key_text = encryptionKeyTextBox.Text.Trim();

                if (key_text.Length != 32)
                {
                    throw new Exception("Invalid generation key provided");
                }

                var key = new byte[16];
                for (int i = 0; i < 32; i += 2)
                {
                    key[i / 2] = Convert.ToByte(key_text.Substring(i, 2), 16);
                }

                string result = decoder.DecryptMessage(message, key);

                recoveredMessageTextBox.Text = result;
            }
            catch (Exception ex)
            {
                //write message to status bar
            }
        }
Ejemplo n.º 2
0
        private void EncryptAndEncode(string encodedFilePath)
        {
            try
            {
                var random = new RNGCryptoServiceProvider();
                var key    = new byte[16];
                random.GetBytes(key);

                string key_text = string.Empty;
                foreach (byte b in key)
                {
                    key_text += string.Format("{0:x2}", b);
                }
                generatedKeyTextBox.Text = key_text;

                AudioEncoder encoder = new AudioEncoder();

                if (string.IsNullOrEmpty(loadedFilePathTextBox.Text))
                {
                    throw new Exception("Base file was not selected");
                }

                encoder.WavToBytes(loadedFilePathTextBox.Text);

                if (string.IsNullOrEmpty(plaintextTextBox.Text))
                {
                    throw new Exception("Message was not provided");
                }

                byte[] encrypted = encoder.EncryptMessage(plaintextTextBox.Text, key);
                encoder.AddMessage(encrypted);
                encoder.BytesToWav(encodedFilePath);
            }
            catch (Exception ex)
            {
                //write message to status bar or whatever
            }
        }