ITPub博客

首页 > Linux操作系统 > Linux操作系统 > SecureString 速记

SecureString 速记

原创 Linux操作系统 作者:kirinri 时间:2009-02-02 17:06:27 0 删除 编辑

        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/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2007-12-21

  • 博文量
    257
  • 访问量
    499423