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 } }