title: C# protect string in memory
body: <p>I'm updating a C# project to make it more secure (I got very strict requirements for it). One of the requirement is to protect some data in memory to prevent "unauthorized" access to it. I made my research and ended up with "ProtectedMemory.Protect". I'm not expert in C#, so I'm not sure if doing it right or not. 
  A simplified example how I implemented it:</p>
  
  <pre><code>public class User
  {
      public string Name
      { 
          get 
          { 
              return Encoding.UTF8.GetString(ProtectedMemory.Unprotect(_name, MemoryProtectionScope.SameLogon)); 
          }
          set 
          { 
              _name =  Encoding.UTF8.GetBytes(value);
              ProtectedMemory.Protect(_name, MemoryProtectionScope.SameLogon);
          }
      }
  
      private byte[] _name;
  }
  </code></pre>
  
  <p>Is this makes sense at all? :D</p>