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.WriteLi ne("testing serialization.. .");
Stream fs = new
FileStream("ser ialtest.xml",Fi leMode.Create,F ileAccess.ReadW rite);
IFormatter formatter = new SoapFormatter() ;
RSAParameters rsap = BobRSA.ExportPa rameters(true); //we want the private
portions
formatter.Seria lize(fs,rsap); //rsap.D is set, along with all private key
portions
fs.Close();
//deserialize
Stream nfs = new FileStream("ser ialtest.xml",Fi leMode.Open,Fil eAccess.Read);
IFormatter defmt = new SoapFormatter() ;
RSAParameters rp = (RSAParameters) defmt.Deseriali ze(nfs);
BobRSA.ImportPa rameters(rp); // rp.D is null, all private portions are.
public Exponet and modulus is set properly
nfs.Close(); 2 8343
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.R SACryptoService Provider(1024)
Dim r As System.Security .Cryptography.R SAParameters
r = rs.ExportParame ters(True)
Dim ms As New System.IO.Memor yStream
Dim x As New Xml.Serializati on.XmlSerialize r(r.GetType)
x.Serialize(ms, r)
ms.Flush()
MsgBox(System.T ext.Encoding.AS CII.GetString(m s.ToArray()))
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*******@post mark.no.spam.pl z.net> wrote in message
news:O0******** ******@TK2MSFTN GP10.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.WriteLi ne("testing serialization.. ."); Stream fs = new FileStream("ser ialtest.xml",Fi leMode.Create,F ileAccess.ReadW rite); IFormatter formatter = new SoapFormatter() ; RSAParameters rsap = BobRSA.ExportPa rameters(true); //we want the private portions formatter.Seria lize(fs,rsap); //rsap.D is set, along with all private key portions fs.Close();
//deserialize Stream nfs = new
FileStream("ser ialtest.xml",Fi leMode.Open,Fil eAccess.Read); IFormatter defmt = new SoapFormatter() ; RSAParameters rp = (RSAParameters) defmt.Deseriali ze(nfs); BobRSA.ImportPa rameters(rp); // rp.D is null, all private portions are. public Exponet and modulus is set properly nfs.Close();
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 writing an accounting application. I have a chart of
accounts in the form of a containment hierarchy. A GeneralLedger contains a
number of Accounts, and each of these Accounts can contain a Aubledger,
which contains its own Accounts, and so on. The...
|
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 something like
this:
RSACryptoserviceProvider rsa = new RSACryptoServiceProvider();
RSAParameters params = webService.GetRSAParameters();
|
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 a class called Point which has 2 variables X and
Y.
I save a few jobs (by serializing), and then enhance my application by
adding a Z variable.
How will serializing behave when loading those jobs that were created before
Z was added?
|
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 question. The interesting thing
is that at each step of the way, DAL & Biz, the someType class is decorated
with the Serializable attribute. And the someTypes collection in the web
method is correctly populated with the data after the call to...
|
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 of time for any help or feedback.
Cheers,
Peter
| |
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>
..
|
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
|
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 portability because of
different compilers packing structures into different sizes or
components of this structure to different address boundaries (for
example placing in multiples of 4 on a 32bit system)? Once the file is
serialized, does the same...
|
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 parameters. But openssl names the parameters
different to the RSAParameters struct. The openssl output is in the form
openssl rsa -in key.pem -noout -text
modulus: ...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |