Problems with RSA.SignData

From: Chris Austin (c.austin_at_bigfoot.com)
Date: 03/24/05


Date: Thu, 24 Mar 2005 10:18:58 -0000

Hi,

I am trying to using the RSACryptoServiceProvider.SignData function to sign
large byte arrays (from 30k to several MBs) and then write them to disk.

The problem is when I am calling the SignData method within a loop for many
arrays. In my test I am reading a series of 100 1MB files into a stream and
signing them, then writing them out again.

When running this test, it progressively uses more and more memory without
freeing any up. However if I just comment out the one line that calls
SignData, I do not have this problem. The memory is not freed until the app
is quit, even if I call GC.Collect. I have limited knowledge of using
SOS.dll for debugging, however, using this it seems that the memory is all
used up by byte arrays.

So why when I call SignData are the byte arrays not garbage collected, but
when I don't they are. Is there a bug in the SignData method that retains a
reference to the byte arrays?

Thanks for any help,

Chris

--------------------------
Private Function SignImage() As Boolean
    Dim Signature() As Byte
    Dim RSA As RSACryptoServiceProvider
    Dim csp As CspParameters
Try
csp = New CspParameters
csp.Flags = CspProviderFlags.UseMachineKeyStore
csp.KeyContainerName = "Capgen.Capsure.SecureImage"
RSA = New RSACryptoServiceProvider(csp)
Signature = RSA.SignData(Image, "SHA1")
WriteString("<Signature>")
WriteBytes(Signature)
WriteString("</Signature>" & vbNewLine)
Signature = Nothing
Return True
Catch ex As Exception
Return False
Finally
Signature = Nothing
If Not RSA Is Nothing Then RSA.Clear()
RSA = Nothing
csp = Nothing
End Try
End Function



Relevant Pages

  • Re: Code calls method with wrong signature (object vs object[])
    ... where the signature only accepts a single object. ... My guess is since object is the base class of most items ... arrays of value types aren't. ...
    (microsoft.public.dotnet.languages.csharp)
  • COMException - Type Mismatch - VARIANT* and SAFEARRAY
    ... I'm trying to call a COM method that has the following signature: ... int32 Foobar; ... arrays and wrapping them in objects, ... C++/VB library that will accept the raw SAFEARRAY, wrap it, and pass it to ...
    (microsoft.public.dotnet.framework.interop)
  • OpenSSL DSA_do_verify equivalent
    ... I'm looking for a win32 equivalent to the below OpenSSL code, verifying a ... signature on a hash. ... P,Q,G,Y and R,S are given as byte arrays. ...
    (microsoft.public.platformsdk.security)
  • Re: Cryptography: RSA Questions
    ... RSA is a standard and implementations of the RSA algorithm exist for ... Encryption keys are just byte arrays. ... implementations use little endian while others use big endian for their ... XML file and put in the key values? ...
    (microsoft.public.dotnet.framework)