views:

78

answers:

4

hi I have a class like Employee. This class has some fields like Id,Name,Surname, Tasks( a string array) , isManager , TaskDueDates ( a date-time array). I want to generate a text from this object. I think to use seperators, this is a basic solution. For example my text can be: 13;George;Smith;{"Task1","Task2","Task3"},false, {this night,nextweek}

But if one of the fields of the object includes this seperator characters; program will not work. After I generate the text; I want to encryp it with MD5 by using some key. This will generate some encrypted data like asp .net viewstate information. Program will also decrypt this encrypted data to the source object.

How can I do this? I am using Asp .Net 2005

+3  A: 

MD5 is no encryption. It's a hashing algorithm. If you create a MD5 out of some data, it is not possible to create the data out of the hash. See http://en.wikipedia.org/wiki/Cryptographic_hash_function for more details.

For your question: try this link http://www.codeproject.com/KB/security/SimpleEncryption.aspx

Tobias Langner
+1  A: 

First of all you cannot decrypt MD5, you need a real encryption algorithm for this. You might want to use AES256.

As for the fields, Unix has had field seperated text forever, and they usually put a '\' in front of any character that is normally special, but shouldn't be in this case (if you want to use a '\' in the text, you write '\'). You could steal that.

Edit: If you are using ASP, why don't you format the output as HTML? Then you could put the output in a table.

tomjen
Are there any other method instead of using seperators?Can serialize be used for this goal?
Yes, they can be used
vitaly.v.ch
A: 

As already mentioned in the answers that for encryption you will need to use some encryption algorithm like AED or DES (http://en.wikipedia.org/wiki/List_of_algorithms#Cryptography).

For serialization, that is converting your object to string you can make your own scheme like using ";" as a separator. To handle the cases where input contains ";", you will need to convert ";" to something else like "\;". Your serialized object will look something like this

Name: Geor;ge

3;Geor\;ge;Smith;{"Task1","Task2","Task3"};false;{this night,nextweek}

When converting back to object, whenever you find '\' before the ';' you will know that this ';' is part of string and not the actual separator.

About using language serialize feature, yes you should be able to do that but that depends on the language on you are working on.

Babar
A: 

Instead of doing manual serialization, if you want your object in a human-readable format, use automatic XML serialization:

XmlSerializer formatter;

using (FileStream file = new FileStream (Path.Combine (Application.StartupPath, GetType ().ToString () + ".xml.template"), FileMode.Create)) { formatter = new XmlSerializer (typeof (G)); formatter.Serialize (file, this); }

With XML serialization make sure the members you want in the XML file are public. private and protected will not be XML serialized.