Click here to Skip to main content
15,172,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friend I first I am taking an text data in string veriable & then i am transfering it to Encrypt function which encrypts string using DES algo it is giving me correct string by incrypting but in next step i am writing that string to wave file means i am hiding string in wave file but at the time of hiding string in wave file it si not hiding whole string it is just hiding first 11 charactes those there are 16 charcter in the encrypted why it is not hiding whole string.
but one thing is there if i hide the same encrypted string by hardcoded way means instead of calling to encrypt function i am directly assigning some value to string veriable in that case it is working fine & hiding all the string without any problem.i have attached my both function
ENCRYPT function & Hide data function here please review it & help me thank you

 private void btnHide_Click(object sender, EventArgs e)
            BinaryWriter messageWriter = new BinaryWriter(new MemoryStream());
            Stream sourceStream = null;
            FileStream destinationStream = null;
            WaveStream audioStream = null;

            //create a stream that contains the message, preceeded by its length

            string encryptDatas =txtMessage.Text;  //Encrypt(txtMessage.Text);
            messageWriter.Seek(0, SeekOrigin.Begin);

            Stream messageStream = messageWriter.BaseStream;
            //open the key file
            Stream keyStream = new FileStream(txtKeyFile.Text, FileMode.Open);


                //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.");

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

                this.Cursor = Cursors.WaitCursor;

                //create an empty file for the carrier wave
                destinationStream = new FileStream(txtDstFile.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 (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);
                MessageBox.Show("data is hided");
            catch (Exception ex)
                this.Cursor = Cursors.Default;
                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;

public string Encrypt(string originalString)
            byte[] bytes = ASCIIEncoding.ASCII.GetBytes("ZeroCool");
            if (String.IsNullOrEmpty(originalString))
                throw new ArgumentNullException
                       ("The string which needs to be encrypted can not be null.");
            DESCryptoServiceProvider cryptoProvid = new DESCryptoServiceProvider();
            MemoryStream memoryStre = new MemoryStream();
            CryptoStream cryptoStre = new CryptoStream(memoryStre,
                cryptoProvid.CreateEncryptor(bytes, bytes), CryptoStreamMode.Write);
            StreamWriter writer = new StreamWriter(cryptoStre);
            byte[] bb = memoryStre.GetBuffer();
            int l=(int)memoryStre.Length;
            return Convert.ToBase64String(bb, 0,l );

without decrypting i am just showing what string is get encrypted , I have function to decrypt also but there is problem in writeing encrypted string only when i give same encrypted string by hard coding it gives me correct out put but when i call to encrypt method those it send correct string encrypting but also when goes to write it does not write whole sting in wave please help me on it .Thanks.
Updated 24-Mar-16 4:38am

1 solution

I think it is because you calculate the length from the txtMessage textbox:

You should calculate it from the string you get after calling the:
Richard Deeming 24-Mar-16 9:41am
This question is from almost four years ago. I doubt the OP is still waiting for an answer.
RickZeeland 24-Mar-16 9:43am
Why do see it on top of the "active" questions ?
Richard MacCutchan 24-Mar-16 10:01am
Because someone else has most likely posted a non-answer, or spam message here, which has since been deleted.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900