encryption - Encrypted Serialization of Objects in C# -


i storing datatable in file using function given below had taken website. code works well.

the problem is:

i want apply sort of encryption here. how can achieve that?

    public void serializeobject<t>(t serializableobject, string filename)     {         if (serializableobject == null) { return; }          try         {             xmldocument xmldocument = new xmldocument();             xmlserializer serializer = new xmlserializer(serializableobject.gettype());             using (memorystream stream = new memorystream())             {                 serializer.serialize(stream, serializableobject);                 stream.position = 0;                 xmldocument.load(stream);                 xmldocument.save(filename);                 stream.close();             }         }         catch (exception ex)         {             //log exception here         }     } 

any highly appreciated.

thanks

encrypt/decrypt streamed xml file given below class: can use encryption strategy depending on requirements.

public static class encryptionmanagement {   private static symmetricalgorithm encryption;   private const string password = "admin";   private const string mkey = "my secret key";    private static void init()   {     encryption = new rijndaelmanaged();     var key = new rfc2898derivebytes(password, encoding.ascii.getbytes(mkey));      encryption.key = key.getbytes(encryption.keysize / 8);     encryption.iv = key.getbytes(encryption.blocksize / 8);     encryption.padding = paddingmode.pkcs7;   }    public static void encrypt(stream instream, stream outstream)   {     init();     var encryptor = encryption.createencryptor();     instream.position = 0;     var encryptstream = new cryptostream(outstream, encryptor, cryptostreammode.write);     instream.copyto(encryptstream);     encryptstream.flushfinalblock();   }     public static void decrypt(stream instream, stream outstream)   {     init();     var encryptor = encryption.createdecryptor();     instream.position = 0;     var encryptstream = new cryptostream(instream, encryptor, cryptostreammode.read);     encryptstream.copyto(outstream);     outstream.position = 0;   } } 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -