Today I’ve had to look at System.Security.SecureString to store passwords. I would have never in my wildest dreams thought that you will have to use System.Runtime.InteropServices.Marshal to convert the SecureString value to an IntPtr and then convert that back to string.
Example:
public SecureString Value { get;set;}
public void DisplaySecureString(){var valuePtr = Marshal.SecureStringToBSTR( Value );var stringValue = Marshal.PtrToStringBSTR( valuePtr );Console.WriteLine( stringValue );}
Advertisement