static void Main(string[] args)
{
System.Security.SecureString ss = new System.Security.SecureString();

string plainText = "SecureStringTest";

foreach (char ch in plainText.ToCharArray())
{
ss.AppendChar(ch);
}

IntPtr ps = System.Runtime.InteropServices.Marshal.SecureStringToBSTR(ss);

IntPtr ps2 = System.Runtime.InteropServices.Marshal.SecureStringToCoTaskMemAnsi(ss);

IntPtr ps3 = System.Runtime.InteropServices.Marshal.SecureStringToCoTaskMemUnicode(ss);

IntPtr ps4 = System.Runtime.InteropServices.Marshal.SecureStringToGlobalAllocAnsi(ss);

IntPtr ps5 = System.Runtime.InteropServices.Marshal.SecureStringToGlobalAllocUnicode(ss);

string result = System.Runtime.InteropServices.Marshal.PtrToStringBSTR(ps);

string result2 = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(ps2);

string result3 = System.Runtime.InteropServices.Marshal.PtrToStringUni(ps3);

string result4 = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(ps4);

string result5 = System.Runtime.InteropServices.Marshal.PtrToStringUni(ps5);

}
}

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12476590/viewspace-545045/,如需转载,请注明出处,否则将追究法律责任。

广播电视节目制作经营许可证(京) 字第1234号 中国互联网协会会员