How would I get a byte[]
equivalent of a SecureString
(which I get from a PasswordBox
)?
My objective is to write these bytes
Per this, http://www.microsoft.com/indonesia/msdn/credmgmt.aspx, you can marshal it into a stock C# string and then convert that into an array of bytes:
static string SecureStringToString( SecureString value )
{
string s ;
IntPtr p = Marshal.SecureStringToBSTR( value );
try
{
s = Marshal.PtrToStringBSTR( p ) ;
}
finally
{
Marshal.FreeBSTR( p ) ;
}
return s ;
}
or per this answer, How to convert SecureString to System.String?, you can use Marshal.ReadByte
and Marshal.ReadInt16
on the IntPtr
to get what you need.