There is a specific requirement I have in my present implementation. Need to maintain a data store in the application in which some of the data needed to be stored and fetched whenever application launched again. To achieve created class in Singleton and made it serialized. Some of the objects in the class are not serialized.
I will be posting the implementation of Singleton class object later. Following is the implementation where class object has been serialized and de-serialized. I also have a requirement to encrypt the data.
To achieve this used DESCryptoServiceProvider and CryptoStream.
"TestStoreObj" is the class object which is in Singleton and I am serializing it here.
Note :- You can use Triple DES for it but it will impact performance due to multiple iteration of encryption.
Reference:
http://msdn.microsoft.com/en-us/library/system.security.cryptography.des.aspx
I will be posting the implementation of Singleton class object later. Following is the implementation where class object has been serialized and de-serialized. I also have a requirement to encrypt the data.
To achieve this used DESCryptoServiceProvider and CryptoStream.
"TestStoreObj" is the class object which is in Singleton and I am serializing it here.
Note :- You can use Triple DES for it but it will impact performance due to multiple iteration of encryption.
Implementation:
Referred following
using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters; using System.Runtime.Serialization.Formatters.Binary; using System.Security.Cryptography;
Initialization
DESCryptoServiceProvider cryptic = new DESCryptoServiceProvider(); IFormatter formatter = new BinaryFormatter(); Stream stream = null;
Serialize
stream = new FileStream("MyConfig.txt", FileMode.Create, FileAccess.Write, FileShare.None); using (CryptoStream cs = new CryptoStream(stream, new DESCryptoServiceProvider().CreateEncryptor(cryptic.Key, cryptic.IV), CryptoStreamMode.Write)) { formatter.Serialize(cs, TestStoreObj); cs.FlushFinalBlock(); } stream.Close();
Deserialize
stream = new FileStream("MyConfig.txt", FileMode.Open, FileAccess.Read, FileShare.None); using (CryptoStream cs = new CryptoStream(stream, new DESCryptoServiceProvider().CreateEncryptor(cryptic.Key, cryptic.IV), CryptoStreamMode.Read)) { TestStoreObj = (TestSingletonClass)formatter.Deserialize(cs); } stream.Close();
Reference:
http://msdn.microsoft.com/en-us/library/system.security.cryptography.des.aspx
Thanks for the docs. While I realize this was written several years ago, I believe there's a bug in the Deserialize code. The code should be calling DESCryptoServiceProvider().CreateDecryptor not DESCryptoServiceProvider().CreateEncryptor.
ReplyDeleteThanks for sharing the information. Keep the good work going.Subway Surfers mod apk Mini Militia Mod
ReplyDeleteIf you are in Jaipur and need beautiful Jaipur Escorts or white skin Jaipur Escorts then you can simply book call girls in Jaipur from one of the best escort agency named Jaipur Escorts. It is No.1 premier escort agency and provide both incall or outcall facility to clients.Please click on the following link to check the official websites Jaipur Escorts
ReplyDeleteCall Girls in Kolkata
ReplyDeleteCall Girls in Mumbai
Call Girls in Lucknow
Call Girls in Gurgaon
Call Girls in Bangalore
Call Girls in Guwahati
======================
Escorts
======================
Escorts in Kolkata
Escorts in Mumbai
Escorts in Lucknow
Escorts in Gurgaon
Escorts in Bangalore
Escorts in Guwahati
Escort services
======================
Escort services in Kolkata
Mumbai Escort Service
Escort services in Lucknow
Escort services in Gurgaon
Escort services in Bangalore
Escort services in Guwahati
======================
Escort service
======================
Escort Service in Kolkata
Escort Service in Mumbai
Escort Service in Lucknow
Escort Service in Gurgaon
Escort Service in Bangalore
Escort Service in Guwahati
👉Escorts in Jaipur
ReplyDelete👉Escorts in Jaipur
👉Escorts in Jaipur
👉Escorts in Delhi
👉Escorts in Guwahati
👉Escorts in Guwahati
👉Escorts in Guwahati
👉Escorts in Guwahati