Clearing out a c# byte array with sensitive data
c#, passwords
Solution
I cannot think of any circumstance in which a call to `Array.Clear` would ever be optimized away and even if it could it would only be optimized away in instances where your `byte[]` was cleared already.
Edit: Something else to consider would be finding out if the framework's `SecureString` implementation would be useful in your situation:
A `SecureString` object is similar to a `String` object in that it has a text value. However, the value of a SecureString object is automatically encrypted, can be modified until your application marks it as read-only, and can be deleted from computer memory by either your application or the .NET Framework garbage collector
Problem
I have a c# byte[] containing sensitive data. What is the best way to clear it? How do I ensure that something like Array.Clear will not be optimized away?