コード例 #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
ファイル: Home.cs プロジェクト: Cryospasm/Steganography
        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;
                }
            }
        }