Beispiel #1
0
        private void btnHide_Click(object sender, EventArgs e)
        {
            // Kayıt
            SaveFileDialog dlg = new SaveFileDialog();

            GetFileName(dlg, txtDstFile, true);

            // Tanımlamalar
            Stream     sourceStream      = null;
            FileStream destinationStream = null;
            WaveStream audioStream       = null;

            //Mesaj tanımalama
            Stream messageStream = GetMessageStream();
            //Key atama
            Stream keyStream = new FileStream(txtKeyFile.Text, FileMode.Open);

            try
            {
                //Max valuedan fazla ise hata ver
                long countSamplesRequired = WaveUtility.CheckKeyForMessage(keyStream, messageStream.Length);

                if (countSamplesRequired > Int32.MaxValue)
                {
                    throw new Exception("Mesaj çok uzun ya da key yanlış.  " + countSamplesRequired + " " + Int32.MaxValue);
                }

                sourceStream = new FileStream(txtSrcFile.Text, FileMode.Open);

                this.Cursor = Cursors.WaitCursor;

                // Dosya oluştur
                destinationStream = new FileStream(txtDstFile.Text, FileMode.Create);

                // Header kopyala
                audioStream = new WaveStream(sourceStream, destinationStream);
                if (audioStream.Length <= 0)
                {
                    throw new Exception("Invalid WAV file");
                }

                // Taşıyıcı veride yeteri kadar yer var mı?
                if (countSamplesRequired > audioStream.CountSamples)
                {
                    String errorReport = "Taşıyıcı veri çok küçük!\r\n"
                                         + "Müsait alan: " + audioStream.CountSamples + "\r\n"
                                         + "Gerekli alan: " + countSamplesRequired;
                    throw new Exception(errorReport);
                }

                // Mesajı gizle
                WaveUtility utility = new WaveUtility(audioStream, destinationStream);
                utility.Hide(messageStream, keyStream);
            }
            catch (Exception ex)
            {
                this.Cursor = Cursors.Default;
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (keyStream != null)
                {
                    keyStream.Close();
                }
                if (messageStream != null)
                {
                    messageStream.Close();
                }
                if (audioStream != null)
                {
                    audioStream.Close();
                }
                if (sourceStream != null)
                {
                    sourceStream.Close();
                }
                if (destinationStream != null)
                {
                    destinationStream.Close();
                }
                this.Cursor = Cursors.Default;
            }
        }
Beispiel #2
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        GoogleDriveFilesRepository grsp = new GoogleDriveFilesRepository();
        DriveService driveService       = grsp.GetService();
        var          fileId             = db.GetIDdrive(TextBox1.Text);
        var          request            = driveService.Files.Get(fileId);
        var          stream             = new System.IO.MemoryStream();

        Label1.Text = fileId;

        // Add a handler which will be notified on progress changes.
        // It will notify on each chunk download and when the
        // download is completed or failed.
        request.MediaDownloader.ProgressChanged +=
            (IDownloadProgress progress) =>
        {
            switch (progress.Status)
            {
            case DownloadStatus.Downloading:
            {
                Console.WriteLine(progress.BytesDownloaded);
                break;
            }

            case DownloadStatus.Completed:
            {
                Console.WriteLine("Download complete.");
                break;
            }

            case DownloadStatus.Failed:
            {
                Console.WriteLine("Download failed.");
                break;
            }
            }
        };
        request.Download(stream);
        SaveStreamToFile(fullPath + "temp.wav", stream);


        {
            Stream     sourceStream      = null;
            FileStream destinationStream = null;
            WaveStream audioStream       = null;

            //create a stream that contains the message, preceeded by its length
            Stream messageStream = GetMessageStream();
            //open the key file
            Stream keyStream = new FileStream(fullPath + "hash.txt", FileMode.Open);

            try
            {
                //how man samples do we need?
                long countSamplesRequired = WaveUtility.CheckKeyForMessage(keyStream, messageStream.Length);

                if (countSamplesRequired > Int32.MaxValue)
                {
                    throw new Exception("Message too long, or bad key! This message/key combination requires " + countSamplesRequired + " samples, only " + Int32.MaxValue + " samples are allowed.");
                }

                sourceStream = new FileStream(fullPath + "temp.wav", FileMode.Open);

                //create an empty file for the carrier wave
                destinationStream = new FileStream(fullPath + "temp2.wav", FileMode.Create);

                //copy the carrier file's header
                audioStream = new WaveStream(sourceStream, destinationStream);
                int a = audioStream.Format.wBitsPerSample;
                if (audioStream.Length <= 0)
                {
                    throw new Exception("Invalid WAV file");
                }

                //are there enough samples in the carrier wave?
                if (countSamplesRequired > audioStream.CountSamples)
                {
                    String errorReport = "The carrier file is too small for this message and key!\r\n"
                                         + "Samples available: " + audioStream.CountSamples + "\r\n"
                                         + "Samples needed: " + countSamplesRequired;
                    throw new Exception(errorReport);
                }

                //hide the message
                WaveUtility utility = new WaveUtility(audioStream, destinationStream);

                utility.Hide(messageStream, keyStream);
            }


            catch (Exception ex)
            {
            }
            finally
            {
                if (keyStream != null)
                {
                    keyStream.Close();
                }
                if (messageStream != null)
                {
                    messageStream.Close();
                }
                if (audioStream != null)
                {
                    audioStream.Close();
                }
                if (sourceStream != null)
                {
                    sourceStream.Close();
                }
                if (destinationStream != null)
                {
                    destinationStream.Close();
                }
            }
        }

        // It's a file name displayed on downloaded file on client side.
        string FileName = fullPath + "temp2.wav";

        System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
        response.ClearContent();
        response.Clear();
        response.ContentType = "audio/mpeg";
        response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + ";");
        response.TransmitFile(FileName);
        response.Flush();
        response.End();
    }