Re: Creating a DSACryptoServiceProvider without generating new Keys

From: Mike Grasso (mgrasso2_at_tampabay.rr.com)
Date: 06/26/03


Date: 26 Jun 2003 07:47:57 -0700


Sebastien

That worked perfectly. I owe you a beer.

"Sebastien Pouliot" <spouliot@motus.com> wrote in message news:<OtwYWQ1ODHA.2480@tk2msftngp13.phx.gbl>...
> Mike,
>
> CspParameter is the "key" to your problem because reusing a container won't
> regenerated a new key pair.
>
> Note: I've noticed some problems, with RSA, when importing a keypair with a
> different length (e.g. container use 1024 bits and you import a 2048 bits
> keypair). However I don't know if this affects the DSA implementation.
>
> Sample code
> --------------------------------------------------------------
> using System;
> using System.Security.Cryptography;
>
> namespace dsa
> {
> class Class1
> {
> [STAThread]
> static void Main(string[] args)
> {
> DateTime dt = DateTime.UtcNow;
> DSA dsa = new DSACryptoServiceProvider ();
> Console.WriteLine ("No CspParameters: {0} seconds", (DateTime.UtcNow -
> dt));
>
> dt = DateTime.UtcNow;
> CspParameters p = new CspParameters (13, null, "motus");
> dsa = new DSACryptoServiceProvider (p);
> Console.WriteLine ("With CspParameters: {0} seconds", (DateTime.UtcNow -
> dt));
> }
> }
> }
> --------------------------------------------------------------
>
> On first time a new keypair must be generated in each case.
>
> Output (first time)
> No CspParameters: 00:00:00.7656201 seconds
> With CspParameters: 00:00:00.1562490 seconds
>
> On subsequent times the constructor using a CspParameter doesn't generate a
> key pair (and is much faster).
>
> Output
> No CspParameters: 00:00:00.4843719 seconds
> With CspParameters: 00:00:00 seconds
>
> Please send the unneeded "War and Peace" books to my address ;-)
> --------------------------------------------------------------
> Sébastien Pouliot
> Architecte Sécurité / Security Architect
> Motus Technologies
> tel: 418 521 2100 ext 225
> fax: 418 521 2101
> courriel / email: spouliot@motus.com
>
> "Mike Grasso" <mgrasso2@tampabay.rr.com> wrote in message
> news:5ea0aa04.0306241244.29ba1dee@posting.google.com...
> > Hey all,
> >
> > If you construct a DSACryptoServiceProvider(), it will generate a new
> > pair of keys. That's great and all , but I already have my keys.
> > I've played around with the CspParameters, but that just deals with
> > the MachineKeyStore. This app will be sitting on a client who will
> > only have my public key. I'd like to load the key using
> > FromXmlString(). My problem is that when I construct the
> > DSACryptoServiceProvider, it takes over 8 seconds. This is way too
> > long, and I don't need it. I guess I could pop up a copy of War and
> > Peace for the users to read, but I'd like to be able to cut out the
> > unnecessary key generation.



Relevant Pages

  • Re: Private key different; Public key same on Different Machines
    ... will generate an AT_KEYEXCHANGE public/private key pair. ... CSP which one you want to use. ... To use your snk-imported keypair, ...
    (microsoft.public.dotnet.security)
  • Multiple Public/Private Key Pairs
    ... Everything was going fine until I wanted to use a second Public private key pair and it appears that I can only have one per context. ... Encrypt/Decrypt Data using KeyPair 1 ...
    (microsoft.public.platformsdk.security)
  • Re: Multiple Public/Private Key Pairs
    ... You can have 2 key pairs per container. ... only one Exchange key pair and one Signature Key pair. ... > Aquire default context ... > Encrypt/Decrypt Data using KeyPair 1 ...
    (microsoft.public.platformsdk.security)