By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,247 Members | 2,145 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,247 IT Pros & Developers. It's quick & easy.

Encrypt/Decrypt serialized data

P: n/a
Does anyone have some nice code samples?
I need to put some data (confidantial data in a small "database").
I plan to use a xml schema to define the structure and
serialize/deserialize to read/store data with the XmlSerializer class.

But I need to protect the data with some kind of encryption.

Is the idea with the xml schema wrong? Better ideas?
It is, today, a CSV file like
a;b;d;e;f;g
a;b;c;d;e;f etc..

but now I would like to arrange the data in a better way and I thought
xml would be better. I'm not interested in using a real database Sql
Server desktop edition (?). Just a "plain" (encrypted) text file...
Best regards
/Magnus

Mar 16 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
..NET 2.0 have some nice wrappers for the Windows Data Protection API in the
System.Security.Cryptography namespace.
You can have a look at these code examples:
http://www.practicaldot.net/en2/Chap...sting_6_23.htm
http://www.practicaldot.net/en2/Chap...sting_6_24.htm
http://www.practicaldot.net/en2/Chap...sting_6_26.htm

They are extracted from the chapter 6 of my book, Practical .NET2 and C#2.
You can download this chapter freely and get explanations about these
classes here:
http://www.practicaldot.net/en2/Sample.htm

Patrick Smacchia
MVP.NET
Author of Practical .NET2 and C#2 http://www.PracticalDOT.NET
Author of NDepend: http://www.NDepend.com
"SunYour" <su*****@hotmail.com> a écrit dans le message de news:
11**********************@z34g2000cwc.googlegroups. com...
Does anyone have some nice code samples?
I need to put some data (confidantial data in a small "database").
I plan to use a xml schema to define the structure and
serialize/deserialize to read/store data with the XmlSerializer class.

But I need to protect the data with some kind of encryption.

Is the idea with the xml schema wrong? Better ideas?
It is, today, a CSV file like
a;b;d;e;f;g
a;b;c;d;e;f etc..

but now I would like to arrange the data in a better way and I thought
xml would be better. I'm not interested in using a real database Sql
Server desktop edition (?). Just a "plain" (encrypted) text file...
Best regards
/Magnus

Mar 16 '06 #2

P: n/a
Patrick,

Thank you!
But how should I do to be able to encode a text file on one computer
and decode it on another computer as a different user.

ProtectedData.Protect(bMsg , entropy ,
DataProtectionScope.CurrentUser);

I need a data protection scope like DataProtectionScope.None or
something :-)

Aný ideas? Better ways to encode whole text files?

Best regards
/Magnus

Mar 16 '06 #3

P: n/a
Then you should use the crypto algorithm directly without relying on DPAPI
wrappers.
For symmetric algo see:
http://www.practicaldot.net/en2/Chap...sting_6_20.htm
For asymmetric algo see:
http://www.practicaldot.net/en2/Chap...sting_6_22.htm

Patrick Smacchia
MVP.NET
Author of Practical .NET2 and C#2 http://www.PracticalDOT.NET
Author of NDepend: http://www.NDepend.com
"SunYour" <su*****@hotmail.com> a écrit dans le message de news:
11*********************@p10g2000cwp.googlegroups.c om...
Patrick,

Thank you!
But how should I do to be able to encode a text file on one computer
and decode it on another computer as a different user.

ProtectedData.Protect(bMsg , entropy ,
DataProtectionScope.CurrentUser);

I need a data protection scope like DataProtectionScope.None or
something :-)

Aný ideas? Better ways to encode whole text files?

Best regards
/Magnus
Mar 16 '06 #4

P: n/a
Thank you!

Do you have a solution on how to deserialize a encrypted xml file as
well?

/Magnus

Apr 5 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.