Пример #1
0
        /// <summary>
        ///   Coverts the SecureString to a regular String.
        /// </summary>
        /// <param name="secureString"> Object value. </param>
        /// <returns> Content of secured String. </returns>
        public static String ToUnsecureString(this SecureString secureString)
        {
            if (secureString.IsNull())
            {
                return(default(String));
            }
            var unmanagedString = IntPtr.Zero;

            try
            {
                unmanagedString = Marshal.SecureStringToGlobalAllocUnicode(secureString);
                return(Marshal.PtrToStringUni(unmanagedString));
            }
            finally
            {
                Marshal.ZeroFreeGlobalAllocUnicode(unmanagedString);
            }
        }