473,473 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Encrypt/Decrypt serialized data

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
4 7551
..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
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
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
Thank you!

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

/Magnus

Apr 5 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: wqhdebian | last post by:
As far as I know,when encrypt or decrypt ,a key must first be got,and the key is first generate by a tool or from SecurityRandom,that means I can not generate the same key with the same input.Does...
1
by: Benoît | last post by:
Hi, I have generated two keys : "C:>openssl req -nodes -new -x509 -keyout ben.key -out ben.crt -days 3650" I try to encrypt/decrypt a string like "JOHN" with these asymetrics keys. With the...
7
by: Matthias S. | last post by:
Hi, I had a look at the vast information on encryption in the MSDN and got pretty confused. All I want to do is to encrypt a string into an encrypted string and later decrypt that (encrypted)...
4
by: Hrvoje Voda | last post by:
Does anyone knows a good example of how to encrypt/decrypt a string? Hrcko
8
by: Gidi | last post by:
Hi, Is there Buid-In fuction in C# that Encrypt and Decrypt strings? i have a textbox which i'm writing into file, and i want to encrypt it before writing, i'm not looking for something fancy,...
1
by: DazedAndConfused | last post by:
Can you encrpt a serialized object? Or am I trying to do something that just doesn't work that way? I am trying to encrypt a serialized object. I can read and write the object to a file...
4
by: Islamegy® | last post by:
I give up.. I tried everything to encrypt querystring and decrypt it back but this never success.. i use RSA encryption. I always get excption when Convert fromBase64String so i tried...
0
by: Ismail Fatih Yýldýrým | last post by:
I modified the RSACSPSample from MSDN to try out a simple commutative encryption model using RSA encryption but when i run the progrem the first encryption command works but during the second...
3
by: JDeats | last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting and decrypting a file. http://support.microsoft.com/kb/307010 In .NET 2.0 this approach is not fully supported (a .NET 2.0...
4
by: Gilles Ganault | last post by:
Hello I'd like to encrypt a customer's organization name to use this as their password to launch our application, and decrypt it within our VB5 application. We will then use this information...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.