title: ProtectedData.Unprotect() after Impersonate()
body: <p>The following code doesn't work:</p>
  
  <pre><code>IntPtr token = Win32Dll.LogonUser(“user1”, “mydomain”, “password1”);
  WindowsIdentity id = new WindowsIdentity(token);
  WindowsImpersonationContext ic = id.Impersonate();
  byte[] unprotectedBytes = ProtectedData.Unprotect(passwordBytes, null, DataProtectionScope.CurrentUser);
  password = Encoding.Unicode.GetString(unprotectedBytes);
  ic.Undo();
  </code></pre>
  
  <p>The password is not decrypted.</p>
  
  <p>MSDN says</p>
  
  <blockquote>
    <p>"If you use this method during impersonation, you may receive the
    following error: "Key not valid for use in specified state." This
    error can be prevented by loading the profile of the user you want to
    impersonate, before calling the method."</p>
  </blockquote>