thank you :)
can i use CryptoStream?

That should work

Product p=new Product();
//stream-this is the stream to the file.
using (MemoryStream ms = new MemoryStream())
            {
                BinaryFormatter msSeri = new BinaryFormatter();
                msSeri.Serialize(ms, p);
                DESCryptoServiceProvider cryptic = new DESCryptoServiceProvider();
                cryptic.Key = ASCIIEncoding.ASCII.GetBytes("ABCDEFGH");
                cryptic.IV = ASCIIEncoding.ASCII.GetBytes("ABCDEFGH");
                CryptoStream crStream = new CryptoStream(ms,cryptic.CreateEncryptor(),CryptoStreamMode.Write);
                byte[] data = ASCIIEncoding.ASCII.GetBytes(ms.ToString());
                crStream.Write(data,0,data.Length);
                crStream.Close();
                BinaryFormatter seri = new BinaryFormatter();
                if (stream != null)
                    seri.Serialize(stream, msSeri.Deserialize(ms));
            }

is this how i'm supposed to do it?

Does CryptoStream implement IDisposable?

If so then wrap that in a using statement too.

So after that, does the code actually work?

seri.Serialize(stream, msSeri.Deserialize(ms));
argument exception in this line-what does it mean?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.