The System.Data.SqlClient.SqlCredential class has a two argument constructor which accepts a username (System.String) and password (System.Security.SecureString).
After calling this constructor, is it safe to dispose the SecureString storing the password? I expect that the SqlCredential class should perform a one-way hash on the password according to the SQL server authentication scheme and not require continued access to the parameter... but perhaps this cannot be done until the connection is opened and a challenge is issued (a nonce may be involved in the HMAC calculation to prevent replay attacks). If SqlCredential does independently keep the needed information, then naturally I want to expedite erasure of the SecureString storage which is reversible.
I have been unable to find any statement in the documentation specifying whether the password SecureString object passed in must remain valid after the SqlCredential constructor returns.
ObjectDisposedExceptionif I dispose the password. But I don't think that is how it should work. SecureString is supposed to be disposed when no longer needed, and if I can't dispose it (because I share an instance withSqlCredential) andSqlCredentialcan't dispose it (because it shares with me) then the sensitive data is going to stay around until the garbage collector decides to invoke the finalizer which finally zeroes it out. - Ben Voigt