Re: Creating a DSACryptoServiceProvider without generating new Keys

From: Sebastien Pouliot (spouliot_at_motus.com)
Date: 06/25/03

  • Next message: Paul: "Enter Network Password--weird error"
    Date: Wed, 25 Jun 2003 15:58:58 -0400
    
    

    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.


  • Next message: Paul: "Enter Network Password--weird error"