Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Speed of signing with RSACryptoServiceProvider

I'm currently working on a simple piece of data signing. It's the first time I use signing so maybe I just do somehting wrong. But I don't think its normal that it takes 4.6 seconds to sign 448 bytes using a 512bit RSA and SHA1 hashing.

The code:

byte[] Data = enc.GetByte(MsgString); //Get Message as byte[]
//Data is 448 bytes long

RSACryptoServiceProvider Crypter = new RSACryptoServiceProvider(512);
Crypter.ImportCspBlob(Convert.FromBase64String(KeyString));

byte[] SignedData = Crypter.SignData(Data, "SHA1"); //Line takes 4.6 seconds

Why is this that slow? I found this : http://support.microsoft.com/kb/948080 , but thats a problem of .NET 2.0. I'm using 4.0.

Is it normal that this takes that long or is there an error?

Thanks for any help.

like image 273
Marks Avatar asked Nov 23 '10 16:11

Marks


1 Answers

Just to let you know that I have been experiencing that same slowness getting SHA1 signed hashes. The some code that usually signed tens on hundreds of transactions per second, sudently, slowed down to 1 for every 5 seconds.

I was working at home and I was not connected to my company's network. After some googling, I have managed to spot the culprit. A bug the seems to afect RSACryptoServiceProvider on .Net Framework 2.0 - which I believe is EXACTLY the same code used on.Net Framework 4.0.

Since, according to http://support.microsoft.com/kb/948080, my temporary slowness may be due both RSACryptoServiceProvider's SignData or VerifyData methods trying to communicate to my companys's domain controller, I have decided to establish a VPN connection to my company, which was an imediate success.

Now I get SHA1 hashes again instantly, instead of waiting up to 5 seconds.

I know this is not a solution, but, at least, is a reasonable workaround. It also prevents us from loosing our sanity.

like image 177
Julio Nobre Avatar answered Nov 12 '22 15:11

Julio Nobre