Exemplo n.º 1
0
        private void btnExtract_Click(object sender, System.EventArgs e)
        {
            Bitmap bitmap = (Bitmap)picImage.Image;

            //empty stream for the extracted message
            Stream messageStream = new MemoryStream();

            //get a stream for the key
            Stream keyStream = GetKeyStream();

            if (keyStream.Length == 0)
            {
                MessageBox.Show("Please enter a password or select a key file.");
                txtKeyText.Focus();
            }
            else
            {
                try{
                    //extract the hidden message from the bitmap
                    CryptUtility.ExtractMessageFromBitmap(bitmap, keyStream, ref messageStream);

                    //save the message, if a filename is available
                    if (txtExtractedMsgFile.Text.Length > 0)
                    {
                        messageStream.Seek(0, SeekOrigin.Begin);
                        FileStream fs            = new FileStream(txtExtractedMsgFile.Text, FileMode.Create);
                        byte[]     streamContent = new Byte[messageStream.Length];
                        messageStream.Read(streamContent, 0, streamContent.Length);
                        fs.Write(streamContent, 0, streamContent.Length);
                    }

                    //display the message - displays chaos, if it's no unicode text
                    messageStream.Seek(0, SeekOrigin.Begin);
                    StreamReader reader        = new StreamReader(messageStream, UnicodeEncoding.Unicode);
                    String       readerContent = reader.ReadToEnd();
                    if (readerContent.Length > txtExtractedMsgText.MaxLength)
                    {
                        readerContent = readerContent.Substring(0, txtExtractedMsgText.MaxLength);
                    }
                    txtExtractedMsgText.Text = readerContent;
                }catch (Exception ex) {
                    MessageBox.Show("Exception:\r\n" + ex.Message);
                }
            }
            //close the streams
            messageStream.Close();
            keyStream.Close();
            bitmap = null;
        }
Exemplo n.º 2
0
        private void btnExtract_Click(object sender, System.EventArgs e)
        {
            Bitmap bitmap        = (Bitmap)picImage.Image;
            Stream messageStream = new MemoryStream();
            Stream keyStream     = GetKeyStream();

            if (keyStream.Length == 0)
            {
                MessageBox.Show("Please enter a password or select a key file.");
                txtKeyText.Focus();
            }
            else
            {
                try{
                    CryptUtility.ExtractMessageFromBitmap(bitmap, keyStream, ref messageStream);
                    if (txtExtractedMsgFile.Text.Length > 0)
                    {
                        messageStream.Seek(0, SeekOrigin.Begin);
                        FileStream fs            = new FileStream(txtExtractedMsgFile.Text, FileMode.Create);
                        byte[]     streamContent = new Byte[messageStream.Length];
                        messageStream.Read(streamContent, 0, streamContent.Length);
                        fs.Write(streamContent, 0, streamContent.Length);
                    }

                    messageStream.Seek(0, SeekOrigin.Begin);
                    StreamReader reader        = new StreamReader(messageStream, UnicodeEncoding.Unicode);
                    String       readerContent = reader.ReadToEnd();
                    if (readerContent.Length > txtExtractedMsgText.MaxLength)
                    {
                        readerContent = readerContent.Substring(0, txtExtractedMsgText.MaxLength);
                    }
                    txtExtractedMsgText.Text = readerContent;
                }catch (Exception ex) {
                    MessageBox.Show("Exception:\r\n" + ex.Message);
                }
            }
            messageStream.Close();
            keyStream.Close();
            bitmap = null;
        }
Exemplo n.º 3
0
        private void btnExtract_Click(object sender, System.EventArgs e)
        {
            //empty stream for the extracted message
            Stream messageStream = new MemoryStream();

            this.Cursor = Cursors.WaitCursor;

            try{
                //extract the hidden message from the bitmap
                CryptUtility.ExtractMessageFromBitmap(imagesExtract, keys, ref messageStream, chkSplitBytes.Checked);

                //save the message, if a filename is available
                if (txtExtractedMsgFile.Text.Length > 0)
                {
                    messageStream.Seek(0, SeekOrigin.Begin);
                    FileStream fs            = new FileStream(txtExtractedMsgFile.Text, FileMode.Create);
                    byte[]     streamContent = new Byte[messageStream.Length];
                    messageStream.Read(streamContent, 0, streamContent.Length);
                    fs.Write(streamContent, 0, streamContent.Length);
                }

                //display the message - displays chaos, if it's no unicode text
                messageStream.Seek(0, SeekOrigin.Begin);
                StreamReader reader        = new StreamReader(messageStream, UnicodeEncoding.Unicode);
                String       readerContent = reader.ReadToEnd();
                if (readerContent.Length > txtExtractedMsgText.MaxLength)
                {
                    readerContent = readerContent.Substring(0, txtExtractedMsgText.MaxLength);
                }
                txtExtractedMsgText.Text = readerContent;
            }catch (Exception ex) {
                MessageBox.Show(ex.Message + "\nStackTrace: " + ex.StackTrace, "Exception");
            }

            this.Cursor = Cursors.Default;

            //close the stream
            messageStream.Close();
        }