Encrypt/Decrypt serialized data


S

SunYour

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
 
Ad

Advertisements

P

Patrick Smacchia

..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/Chapter_6/Listing_6_23.htm
http://www.practicaldot.net/en2/Chapter_6/Listing_6_24.htm
http://www.practicaldot.net/en2/Chapter_6/Listing_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
 
S

SunYour

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
 
P

Patrick Smacchia

Then you should use the crypto algorithm directly without relying on DPAPI
wrappers.
For symmetric algo see:
http://www.practicaldot.net/en2/Chapter_6/Listing_6_20.htm
For asymmetric algo see:
http://www.practicaldot.net/en2/Chapter_6/Listing_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" <[email protected]> a écrit dans le message de (e-mail address removed)...
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
 
Ad

Advertisements

M

Magnus

Thank you!

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

/Magnus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top