C# spot of Bother with Encrypting Binary

Howdy All,

Im making a little App in WPF 3.5 to store Passwords and im very nearly done, however the final thing I want to add is some Encryption to Files that are written just to make it a little harder to read as Binary adds lots of woffle but doesn't acturally conceal much of the data.

As mentioned im using a pretty standard Binary Serilization and Deserialization function and got that working (again another 'first' for me) and having done some searching Ive realised I need to use a CryptoStream, however unless im not really understanding the code in the examples ive come across, they do not combine it with serialization/de-serialization, before writing or reading the files.

The only example I thought would help acturaly mixes Encryption with XML serialisation so using that as a basis ive tried the following.

         public void WritePasswordDetails(List<PassDetails> passwords, string Refname, SymmetricAlgorithm Key)

             IFormatter formatter = new BinaryFormatter();
            using (Stream dataFileStream = File.Create(Refname))
                using(CryptoStream cs = new CryptoStream(dataFileStream,   Key.CreateDecryptor(), CryptoStreamMode.Write))
                    formatter.Serialize(dataFileStream, passwords);

Open in new window

This code  throws no errors in itself. However the Code im using to Write this data is, due to it only taking two Arguements:-

 WritePasswordDetails(passwordlist, (user) +".dat");

Open in new window

Error 1 No overload for method 'WritePasswordDetails' takes 2 arguments      

How do I go about fixing this problem and implimenting this properly?

Many Thanks


Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

you need to pass it the third parameter -- SymmetricAlgorithm Key.

SymmetricAlgorithm itself is an abstract class. So you will need to use one of the concrete classes that derive from it. This MSDN page lists the classes available AES, RC2, etc. e.g.
RC2 Key = RC2.Create();
WritePasswordDetails(passwordlist, (user) +".dat", Key);

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bronco78thAuthor Commented:
That was surprisingly simple.

Even annoyingly so, should have figured that one out myself I feel.

Thanks for your time jhshukla.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.