HighTechTalks DotNet Forums  

First call to RSAParam.export very slow

Dotnet Security microsoft.public.dotnet.security


Discuss First call to RSAParam.export very slow in the Dotnet Security forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
floppyzedolfin
 
Posts: n/a

Default First call to RSAParam.export very slow - 07-30-2007 , 03:01 AM






Hello.
I'm working in Visual Studio, language is C#, and I am coding a
cryptography program.
At some point, I need random values, and rather than using a made-for-
it random generator, I use the first bytes of
RSACryptoServiceProvider.ExportParameters(false).M odulus.

The reason for that is just that I also have a call to that
RSACryptoServiceProvider.ExportParameters(false) further on, and my
problem is that the first call to
RSACryptoServiceProvider.ExportParameters(false) is excessivly slow
(it's in a range of 5 secs to 120 secs), whereas all furtherer calls
are fast (less than 20 ms)

Could there be a reason for that, and could it be avoided?


Here's a part of the code I use :


using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Security.Cryptography;

namespace My_Project
{
class My_Class
{
static void Main() {

RSACryptoServiceProvider RSACrypto = new
RSACryptoServiceProvider(4096);

byte[] My_Hash = new byte[20];
My_Hash[0] = RSACrypto.ExportParameters(false).Modulus[0]; //this
line takes 20 secs, even if it's included inside the loop
for(int i=1; i<20; i++) // this loop is fast enough to be
performed in less than 0.5 sec
{
My_Hash[i] = RSACrypto.ExportParameters(false).Modulus[i];
}
/* blah blah blah */
// do things such as encrypt(data,
RSACrypto.ExportParameters(false));
}
}
}

A few words about that : it's not the entire code, so don't be afraid
of the uselessness of those lines; and, yes, I could've written the
RSACrypto.ExportParameters(false).Modulus into a buffer, but that's
not the point I want to emphatize on right now (since it will not skip
that first call)

Thanks.


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.