Пример #1
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        string     SavePath     = HttpContext.Current.Server.MapPath(string.Format("~/App_Data/"));
        Stream     sourceStream = null;
        WaveStream audioStream  = null;
        //create an empty stream to receive the extracted message
        MemoryStream messageStream = new MemoryStream();
        //open the key file
        Stream keyStream = new FileStream(SavePath + "hash.txt", FileMode.Open);

        try
        {
            //open the carrier file
            sourceStream = FileUpload1.PostedFile.InputStream;
            audioStream  = new WaveStream(sourceStream);
            WaveUtility utility = new WaveUtility(audioStream);

            //exctract the message from the carrier wave
            utility.Extract(messageStream, keyStream);

            messageStream.Seek(0, SeekOrigin.Begin);

            { //display result
                Label1.Text = new StreamReader(messageStream).ReadToEnd();
            }
        }
        catch (Exception ex)
        {
        }
        finally
        {
            if (keyStream != null)
            {
                keyStream.Close();
            }
            if (messageStream != null)
            {
                messageStream.Close();
            }
            if (audioStream != null)
            {
                audioStream.Close();
            }
            if (sourceStream != null)
            {
                sourceStream.Close();
            }
        }
    }
Пример #2
0
        private void btnExtract_Click(object sender, EventArgs e)
        {
            if (txtSrcFile2.Text.Length == 0)
            {
                errorProvider.SetError(txtSrcFile, "Taşıyıcı veri alanını boş bırakmayınız.");
            }
            else if (txtKeyFile2.Text.Length == 0)
            {
                errorProvider.SetError(txtKeyFile, "Bir şifre dosyası seçiniz.");
            }
            else
            {
                this.Cursor = Cursors.WaitCursor;

                FileStream sourceStream = null;
                WaveStream audioStream  = null;
                //Extract etmek için boş bir steam yaratıldı
                MemoryStream messageStream = new MemoryStream();
                //Key file açıldı
                Stream keyStream = new FileStream(txtKeyFile2.Text, FileMode.Open);


                try
                {
                    // Taşıyıcı dosya açıldı
                    sourceStream = new FileStream(txtSrcFile2.Text, FileMode.Open);
                    audioStream  = new WaveStream(sourceStream);
                    WaveUtility utility = new WaveUtility(audioStream);

                    // Mesaj açıldı
                    utility.Extract(messageStream, keyStream);

                    messageStream.Seek(0, SeekOrigin.Begin);
                    // Sonuç dosyaya kaydedildi
                    FileStream fs = new FileStream(txtMessageDstFile.Text + ".txt", FileMode.Create);

                    byte[] buffer = new byte[messageStream.Length];
                    messageStream.Read(buffer, 0, buffer.Length);
                    fs.Write(buffer, 0, buffer.Length);
                    fs.Close();
                }
                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();
                    }
                    this.Cursor = Cursors.Default;
                }
            }
        }
Пример #3
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;
            }
        }
Пример #4
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();
    }