Share via

Does PersistKeyInCsp=false; and Clear() method zero memory?

Anonymous
2023-04-11T14:09:12.65+00:00

According to .NET documentation:

RSAalg.PersistKeyInCsp = false;  
RSAalg.Clear(); 

Above snippet deletes the key from CSP. But I cannot find any information either the memory where private key is stored is securely zeroed once the key is deleted. I looked at the .NET code and Clear() method disposes the object only. In fact, there is ClearPrivateParameters method, but it's private one, and is not used in Clear() at all. Moreover, here we can see that PersistKeyInCsp is not used by anything (there is no reference found in the project) - looks like dead code(?) Am I right, that memory is not zeroed?

Developer technologies | .NET | Other
Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.


1 answer

Sort by: Most helpful
  1. Wenbin Geng 746 Reputation points Microsoft External Staff
    2023-04-12T09:55:32.2033333+00:00

    Hi,

    You are right, Clear() does not have a memory zeroing function. From the documentation, Clear() calls Dispose() and GC.SuppressFinalize(). Dispose(true) will dispose of all resources used by the object and set them to null, then suppress the object's finalizer by calling GC.SuppressFinalize(this) . It just frees any unmanaged resources, but it doesn't guarantee that the managed memory used by the object will be zeroed out.

    Best regards,

    Wenbin Geng


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

     

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.