API is taking time …. – .NET Framework

  .net

Q(Question):

I am trying to fetch public key from DSA certificate using .NET
cryptography API. It is taking 15 to 45 seconds…..


String crtFileName = "C:\mycert.crt";
X509Certificate2 x509 = new X509Certificate2();
byte[] rawData = System.IO.File.ReadAllBytes(crtFileName);
x509.Import(rawData);
// START
DateTime tm = DateTime.Now;
DSACryptoServiceProvider dsa1 = (DSACryptoServiceProvider)
x509.PublicKey.Key; // TAKING 15 to 45 SECONDS
TimeSpan ts = DateTime.Now - tm ;
Console.WriteLine("Extract Public Key : " + ts.ToString
());
// END
HashAlgorithm hashAlgo = HashAlgorithm.Create("SHA1");
byte[] hash = hashAlgo.ComputeHash(data_to_sign);
bool bVar = dsa1.VerifySignature(hash, signature);

Help me to find why API is taking time… ?

A(Answer):

Hi, try to do this:

X509Certificate2 cert = new X509Certificate2(crtFileName);
DSASignatureDeformatter deformatter = new DSASignatureDeformatter(cert.PublicKey.Key);

bool ok = deformatter.VerifySignature(hash, signature);

I tried with the RSA algorithm and it works well. I doesn’t have DSA certificate and so I cannot try it. Are you sure your certificate is well done … ?

If you need some RSA certificate to test you can create them at http://www.we-coffee.com/x509builder.aspx

LEAVE A COMMENT