473,387 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Serializing RSAParameters issues

Hello,

I am wanting to serialize (for storage of an RSA Keypair) a RSAParameters
class. It seems that even if i export the private portions of the Key, they
are never serialized and stored in the file. Only the public portions of the
key are (you can see this by opening up the serialtest.xml file written).

My question is: Am I just missing something very simple here or do I have to
write a custom class to turn a RSAParameters into a completely serializable
one?

I might have to do the second one anyways, so its not a big deal if I have
to (gotta encrypt the private portions of the key, would make sense to just
support this in its class) but if I really have to, id like to understand
why its doing this the way it is.

Ive been using C# for a while, but I have not used serialization yet. so I
might just be missing something.

Thank you for your time, and any ideas you can offer =]

eric.h

Example Code:
Console.WriteLine("testing serialization...");
Stream fs = new
FileStream("serialtest.xml",FileMode.Create,FileAc cess.ReadWrite);
IFormatter formatter = new SoapFormatter();
RSAParameters rsap = BobRSA.ExportParameters(true); //we want the private
portions
formatter.Serialize(fs,rsap); //rsap.D is set, along with all private key
portions
fs.Close();

//deserialize
Stream nfs = new FileStream("serialtest.xml",FileMode.Open,FileAcce ss.Read);
IFormatter defmt = new SoapFormatter();
RSAParameters rp = (RSAParameters)defmt.Deserialize(nfs);
BobRSA.ImportParameters(rp); // rp.D is null, all private portions are.
public Exponet and modulus is set properly
nfs.Close();
Nov 15 '05 #1
2 8317
Try the following, and you'll see that it is possible.
I wrote the code in VB because I thought this question was in the VB group,
but it should be easy enough to figure out the C# conversion.

Dim rs As New System.Security.Cryptography.RSACryptoServiceProvi der(1024)

Dim r As System.Security.Cryptography.RSAParameters

r = rs.ExportParameters(True)

Dim ms As New System.IO.MemoryStream

Dim x As New Xml.Serialization.XmlSerializer(r.GetType)

x.Serialize(ms, r)

ms.Flush()

MsgBox(System.Text.Encoding.ASCII.GetString(ms.ToA rray()))

ms.Close()

-Rob [MVP]
Do not send questions to my email. There will be no response. Please post
comments, responses, and requests to the newsgroup so everyone can benefit
from the discussion.

"Eric" <mr*******@postmark.no.spam.plz.net> wrote in message
news:O0**************@TK2MSFTNGP10.phx.gbl...
Hello,

I am wanting to serialize (for storage of an RSA Keypair) a RSAParameters
class. It seems that even if i export the private portions of the Key, they are never serialized and stored in the file. Only the public portions of the key are (you can see this by opening up the serialtest.xml file written).

My question is: Am I just missing something very simple here or do I have to write a custom class to turn a RSAParameters into a completely serializable one?

I might have to do the second one anyways, so its not a big deal if I have
to (gotta encrypt the private portions of the key, would make sense to just support this in its class) but if I really have to, id like to understand
why its doing this the way it is.

Ive been using C# for a while, but I have not used serialization yet. so I
might just be missing something.

Thank you for your time, and any ideas you can offer =]

eric.h

Example Code:
Console.WriteLine("testing serialization...");
Stream fs = new
FileStream("serialtest.xml",FileMode.Create,FileAc cess.ReadWrite);
IFormatter formatter = new SoapFormatter();
RSAParameters rsap = BobRSA.ExportParameters(true); //we want the private
portions
formatter.Serialize(fs,rsap); //rsap.D is set, along with all private key
portions
fs.Close();

//deserialize
Stream nfs = new FileStream("serialtest.xml",FileMode.Open,FileAcce ss.Read); IFormatter defmt = new SoapFormatter();
RSAParameters rp = (RSAParameters)defmt.Deserialize(nfs);
BobRSA.ImportParameters(rp); // rp.D is null, all private portions are.
public Exponet and modulus is set properly
nfs.Close();

Nov 15 '05 #2
Hello Rob,

Thank you for the code. I did convert it to C# and it does work.
Unfortuneately, that doesnt help me as to why SoapFormatter refuses to work.
Try my code out, you will see it will not work (at least it shouldn't). Is
there something wrong with my code? I can not seem to find it.

Thank you for your help.
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Dave Veeneman | last post by:
When does serializing objects make more sense than persisting them to a database? I'm new to object serialization, and I'm trying to get a feel for when to use it. Here is an example: I'm...
0
by: tam2005 via DotNetMonster.com | last post by:
I'm going to use WebMethod GetRSAParameters in my c# application which returns RSAParameters object. But when I'm trying too include System.Secrity.Cryptography namespace and when I'm writing...
2
by: Simon | last post by:
I'm developing a new application and want to use serialization as a way to save my data. But as I add new variables to my classes, how will serializing cope with that? For example, suppose I have...
3
by: RandomEngineer | last post by:
So here's the challenge... How can a collection (System.Collections.Generic.IList) of some custom type be serialized in a web service using .NET 2.0? Below are the class and the web methods in...
1
by: Peter Nofelt | last post by:
Hey All, I am having issue with serializing a class and its base class using ..net 2.0. I am using IXmlSerializable I've provided code displaying my at the bottom of this post. Thanks ahead...
3
by: Thyme | last post by:
Each time I serialize an object using XmlSerializer I get a structure like this: <?xml version="1.0"?> <MyType> .. .. </MyType> <?xml version="1.0"?> <MyType> ..
4
by: dani k | last post by:
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
12
by: Cagdas Ozgenc | last post by:
Greetings, When directly serializing C++ structures to a file with the standard library functions giving the address of the data and length of structure using the sizeof operator, do I risk...
1
by: SammyBar | last post by:
Hi all, I need to fill a System.Security.Cryptography.RSAParameters structure with my private key parameters. The private key is in PEM format so by using openssl I can obtain all the...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.