SecureString 速记

        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);

        }
    }

请使用浏览器的分享功能分享到微信等