Otis Mukinfus wrote:
On 25 Sep 2006 22:47:42 -0700, "dani k" <da*********@gmail.comwrote:
How do I write my own serialization of a class that has
non-serializable data members?
this problem arose when I tried to serialize RSAParameters, for which
the private stuff is not serializable
I'm afraid you can't serialize the private fields of objects you don't have the
source for, but if the private fields are exposed as properties, you might be
able to inherit from the class and serialize those properties in the derived
class.
Did I misunderstand your question?
Good luck with your project,
Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
Yes, I am afraid I didn't state the problem very well. Thanks anyway.
Anyway, I figured it out: I included an RSAParameters object as a
member in a new class that implements the ISerializable interface, and
wrote my own serialization code.
It works!
Here is the code:
public class AllSerRSAParameters:ISerializable
{
private RSAParameters RSAKeyInfo;
public AllSerRSAParameters(RSAParameters rhs)
{
RSAKeyInfo = rhs;
}
public AllSerRSAParameters(SerializationInfo si,
StreamingContext context)
{
RSAKeyInfo.D = (Byte[]) si.GetValue( "D", typeof(Byte[]));
RSAKeyInfo.DP = (Byte[]) si.GetValue( "DP",
typeof(Byte[]));
RSAKeyInfo.DQ = (Byte[])si.GetValue("DQ", typeof(Byte[]));
RSAKeyInfo.Exponent = (Byte[])si.GetValue("Exponent",
typeof(Byte[]));
RSAKeyInfo.InverseQ = (Byte[])si.GetValue("InverseQ",
typeof(Byte[]));
RSAKeyInfo.Modulus = (Byte[])si.GetValue("Modulus",
typeof(Byte[]));
RSAKeyInfo.P = (Byte[])si.GetValue("P", typeof(Byte[]));
RSAKeyInfo.Q = (Byte[])si.GetValue("Q", typeof(Byte[]));
}
public RSAParameters GetRSAParameters()
{
return RSAKeyInfo;
}
#region ISerializable Members
[SecurityPermission(SecurityAction.Demand,
SerializationFormatter = true)]
public void GetObjectData(SerializationInfo si,
StreamingContext context)
{
si.AddValue("D", RSAKeyInfo.D, typeof(Byte[]));
si.AddValue("DP", RSAKeyInfo.DP, typeof(Byte[]));
si.AddValue("DQ", RSAKeyInfo.DQ, typeof(Byte[]));
si.AddValue("Exponent", RSAKeyInfo.Exponent,
typeof(Byte[]));
si.AddValue("InverseQ", RSAKeyInfo.InverseQ,
typeof(Byte[]));
si.AddValue("Modulus", RSAKeyInfo.Modulus, typeof(Byte[]));
si.AddValue("P", RSAKeyInfo.P, typeof(Byte[]));
si.AddValue("Q", RSAKeyInfo.Q, typeof(Byte[]));
}
#endregion
}