Welcome to Dream.In.Code
Become a C# Expert!

Join 150,381 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,229 people online right now. Registration is fast and FREE... Join Now!




" Cryptography and Steganography "

 
Reply to this topicStart new topic

" Cryptography and Steganography ", AES and Audio Steganography

dinniit
29 Jan, 2008 - 07:19 AM
Post #1

New D.I.C Head
*

Joined: 29 Jan, 2008
Posts: 1

Hey please anybody help me to devolpe a project for combining both AES and Audio stenography... can anybody give the project ?????
User is offlineProfile CardPM
+Quote Post

skyhawk133
RE: " Cryptography And Steganography "
29 Jan, 2008 - 07:57 AM
Post #2

Head DIC Head
Group Icon

Joined: 17 Mar, 2001
Posts: 15,287



Thanked: 61 times
Dream Kudos: 1650
Expert In: Web Development

My Contributions
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Post your code like this: code.gif

Thanks.
User is online!Profile CardPM
+Quote Post

yunii
RE: " Cryptography And Steganography "
3 Feb, 2008 - 02:24 AM
Post #3

New D.I.C Head
*

Joined: 3 Feb, 2008
Posts: 1

i really confused, how to make some audio steganography using mp3 as the cover...
somebody, please help me...
User is offlineProfile CardPM
+Quote Post

PennyBoki
RE: " Cryptography And Steganography "
3 Feb, 2008 - 02:42 AM
Post #4

system("revolution");
Group Icon

Joined: 11 Dec, 2006
Posts: 2,011



Thanked: 7 times
Dream Kudos: 500
Expert In: Java,C++,C

My Contributions
QUOTE(yunii @ 3 Feb, 2008 - 03:24 AM) *

i really confused, how to make some audio steganography using mp3 as the cover...
somebody, please help me...

Read the post above yours.
User is offlineProfile CardPM
+Quote Post

yuni
RE: " Cryptography And Steganography "
13 Mar, 2008 - 10:34 PM
Post #5

New D.I.C Head
*

Joined: 13 Mar, 2008
Posts: 2


My Contributions
i want to make audio steganography with kriptography (aes). audio cover using wav and midi, i have no problem with wav but really confused with midi. most of code i get from http://codeproject.com..here is the code :
CODE

using System;
using System.Drawing;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace StegAudio
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void buttonnamafile_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            GetFileName(dlg, textBoxHideFile, false);
        }

        private void buttontempatfile_Click(object sender, EventArgs e)
        {
            SaveFileDialog dlg = new SaveFileDialog();
            GetFileName(dlg, textBoxDestFile, true);
        }

        private void GetFileName(FileDialog dialog, TextBox control, bool useFilter)
        {
            if (useFilter) { dialog.Filter = "Wave Audio (*.wav)|*.wav|MIDI (*.mid)|*.mid";}
            if (dialog.ShowDialog(this) == DialogResult.OK)
            {
                control.Text = dialog.FileName;
            }
        }

        private string GetFileExtension(string filename)
        {
            return filename.Substring(filename.Length - 3, 3);
        }

        private void buttoncariaudio_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            GetFileName(dlg, textBoxHideAudio, true);
        }

        private void buttonfileakhir_Click(object sender, EventArgs e)
        {
            SaveFileDialog dlg = new SaveFileDialog();    
            GetFileName(dlg, textBoxExtDest, false);
        }

        private void buttonsembunyi_Click(object sender, EventArgs e)
        {
            if(textBoxHideAudio.Text.Length == 0)
            {
                errorProvider1.SetError(textBoxHideAudio, "You forgot to choose a carrier file."); //errorProvider blom didefinisikan sebelumnya, jadi ngga bisa dipake
            }
            else if(textBoxPWH.Text.Length == 0)
            {
                errorProvider1.SetError(textBoxPWH, "You forgot to write a key.");
            }
            else if(textBoxDestFile.Text.Length == 0)
            {
                errorProvider1.SetError(textBoxDestFile, "The resulting carrier file must be saved somewhere.");
            }
            else if (textBoxHideFile.Text.Length == 0)
            {
                errorProvider1.SetError(textBoxHideFile, "What am I supposed to hide?");
            }
            else
            {
                //before we hide the message into the wav file, we must encrypt it first
                //in this case, we are using Rijndael encryption
                MyEncryptor encryptor = new MyEncryptor(textBoxPWH.Text); //we use the key password as a secret phase
                String encryptedMessage = encryptor.Encrypt(GetMessageString());

                //reset all the stream first
                Stream sourceStream = null;
                FileStream destinationStream = null;
                WaveStream audioStream = null;

                Stream messageStream = GetMessageStream(encryptedMessage); //write the encrypted message into the stream

                Stream keyStream = GetKeyStream();

                string fileExtension; //fileextension indicating the format of audio file as the carrier of the secret message
                fileExtension = GetFileExtension(textBoxHideAudio.Text);
                if (fileExtension.Equals("wav"))
                {
                    try
                    {
                        //how many samples do we need
                        long countSampleRequired = WaveUtility.CheckKeyForMessage(keyStream, messageStream.Length);

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

                        //use wav file as the carrier
                        sourceStream = new FileStream(textBoxHideAudio.Text, FileMode.Open);

                        this.Cursor = Cursors.WaitCursor;

                        //create empty file for the carrier wave
                        destinationStream = new FileStream(textBoxDestFile.Text, FileMode.Create);

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

                        //are there enough samples in the carrier wave?
                        if (countSampleRequired > 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: " + countSampleRequired;
                            throw new Exception(errorReport);
                        }

                        //hide message
                        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;
                        MessageBox.Show("file Telah Sukses Disisipkan");
                    }
                }
                else if (fileExtension.Equals("mid"))
                {
                    //i'll make it simple, coz the method is slightly different in code than wav. Another reason is that i'm lazy enough not to port the code.
                    try
                    {
                        this.Cursor = Cursors.WaitCursor;

                        MidiUtility utility = new MidiUtility();
                        utility.HideMessage(textBoxHideAudio.Text, textBoxDestFile.Text, 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(); }       //actually, these two streams aren't needed in this method
                        if (sourceStream != null) { sourceStream.Close(); }     //but let's write them anyway...:)
                        if (destinationStream != null) { destinationStream.Close(); }
                    }
                }  
            }
        }

        private Stream GetMessageStream()
        {
            BinaryWriter messageWriter = new BinaryWriter(new MemoryStream());

            //open the file to be hidden
            FileStream fs = new FileStream(textBoxHideFile.Text, FileMode.Open);
            int filelength = (int)fs.Length;
            messageWriter.Write(filelength); //save the length of file into binary stream
            byte[] buffer = new byte[fs.Length]; //allocate the buffer as big as the file length
            fs.Read(buffer, 0, filelength); //read the file into the buffer
            messageWriter.Write(buffer); //save the buffer into binary stream
            fs.Close(); //close the file when operation finished

            messageWriter.Seek(0, SeekOrigin.Begin);
            return messageWriter.BaseStream;
        }

        private Stream GetMessageStream(string message)
        {
            BinaryWriter messageWriter = new BinaryWriter(new MemoryStream());

            messageWriter.Write(message.Length);
            messageWriter.Write(Encoding.ASCII.GetBytes(message));

            messageWriter.Seek(0, SeekOrigin.Begin);
            return messageWriter.BaseStream;
        }

        private String GetMessageString()
        {
            FileStream fs = new FileStream(textBoxHideFile.Text, FileMode.Open);
            StreamReader rd = new StreamReader(fs);

            return rd.ReadToEnd();
        }

        private Stream GetKeyStream()
        {
            BinaryWriter keyWriter = new BinaryWriter(new MemoryStream());

            //write the password to the binary stream
            keyWriter.Write(Encoding.ASCII.GetBytes(textBoxPWH.Text));

            keyWriter.Seek(0, SeekOrigin.Begin);
            return keyWriter.BaseStream;
        }

        private void buttonekstract_Click(object sender, EventArgs e)
        {
            if (textBoxHideAudio.Text.Length == 0)
            {
                errorProvider1.SetError(textBoxHideAudio, "You forgot to choose a carrier file.");
            }
            else if (textBoxPWH.Text.Length == 0)
            {
                errorProvider1.SetError(textBoxPWH, "You forgot to write a key.");
            }
            else
            {
                this.Cursor = Cursors.WaitCursor;
                FileStream sourceStream = null;
                WaveStream audioStream = null;
                //create an empty stream to receive the extracted message
                MemoryStream messageStream = new MemoryStream();

                Stream keyStream = GetKeyStream();

                string fileExtension; //fileextension indicating the format of audio file as the carrier of the secret message
                fileExtension = GetFileExtension(textBoxHideAudio.Text);
                if (fileExtension.Equals("wav"))
                {
                    try
                    {
                        //open the carrier file
                        sourceStream = new FileStream(textBoxHideAudio.Text, FileMode.Open);
                        audioStream = new WaveStream(sourceStream);
                        WaveUtility utility = new WaveUtility(audioStream);

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

                        messageStream.Seek(0, SeekOrigin.Begin);

                        //save result to a file
                        FileStream fs = new FileStream(textBoxExtDest.Text, FileMode.Create);

                        //before the result message is saved in the destination file, decrypt it first
                        MyEncryptor decryptor = new MyEncryptor(textBoxPWH.Text); //we use the key password as a secret phase
                        StreamReader rd = new StreamReader(messageStream);
                        String decryptedMessage = decryptor.Decrypt(rd.ReadToEnd());
                        StreamWriter wr = new StreamWriter(fs);

                        wr.Write(decryptedMessage);

                        wr.Flush();
                        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;
                        MessageBox.Show("Ekstraksi Pesan Telah Selesai");
                    }
                }
                else if (fileExtension.Equals("mid"))
                {
                    try
                    {
                        MidiUtility utility = new MidiUtility();
                        utility.ExtractMessage(textBoxHideAudio.Text, null, messageStream, keyStream);

                        messageStream.Seek(0, SeekOrigin.Begin);

                        //save result to a file
                        FileStream fs = new FileStream(textBoxExtDest.Text, FileMode.Create);

                        //before the result message is saved in the destination file, decrypt it first
                        MyEncryptor decryptor = new MyEncryptor(textBoxPWH.Text); //we use the key password as a secret phase
                        StreamReader rd = new StreamReader(messageStream);
                        String decryptedMessage = decryptor.Decrypt(rd.ReadToEnd());
                        StreamWriter wr = new StreamWriter(fs);

                        wr.Write(decryptedMessage);

                        wr.Flush();
                        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;
                        MessageBox.Show("Ekstraksi Pesan Telah Selesai");
                    }
                }
            }
        }
    }
}

please reply my post as soon as posible.
not forget i'm adding attachment for whole program
once more, when i use midi as the cover, it says "invalid file format"...
thanks before


Attached File(s)
Attached File  StegAudio.zip ( 124.5k ) Number of downloads: 190
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 04:12PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month