I am sending Data from a Server to a Client over the Internet using WCF web services in form of Data Objects. I have created a Class, which is Serializable, and using this class to send my data.
Below is an example of my class:
[Serializable]
public class DBOList
{
public string A{ get; set; }
public string B { get; set; }
}
Is it possible for me to Encrypt the data in this object, and send it to the client as a stream?
If not What is the best approach to achive this?
Encryption Code:
DBOList NewLst = new DBOList();
NewLst.A = "Value 1";
NewLst.B = "Value 2";
byte[] key = { 1, 2, 3, 4, 5, 6, 7, 8 };
byte[] iv = { 1, 2, 3, 4, 5, 6, 7, 8 };
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
// Encryption
using (var fs = new MemoryStream())
{
var cryptoStream = new CryptoStream(fs, des.CreateEncryptor(key, iv), CryptoStreamMode.Write);
BinaryFormatter formatter = new BinaryFormatter();
// This is where you serialize the class
formatter.Serialize(cryptoStream, NewLst);
cryptoStream.FlushFinalBlock();
}