Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5844045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:14:22+00:00 2026-05-22T12:14:22+00:00

I recently discovered SecureString and it seems to fit a perfect application where I

  • 0

I recently discovered SecureString and it seems to fit a perfect application where I want to basically initialize a static secret string at the beginning of an application, and then make it read-only and use it throughout the life of the application(as a portion of a hash).

I’m having trouble understanding how to even make use of the SecureString class.. From what I can tell, you can set the SecureString, but there is no way to compare the value or retrieve the value in any way.

What is the purpose of this class if it’s write-only?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:14:22+00:00Added an answer on May 22, 2026 at 12:14 pm

    Both ways here, a way to convert it to a securestring and from a securestring. Of course the whole point of storing it in a securestring is to prevent it from being in memory in the first place.

            #region SecureString Manipulation
        /// <summary>
        /// Convert a Securestring to a regular string (not considered best practice, but make sure it's not in memory if you can help it)
        /// </summary>
        /// <param name="securePassword">Password stored in a secure string</param>
        /// <returns>regular string of securestring password</returns>
        public static string ConvertToUnsecureString(this System.Security.SecureString securePassword)
        {
            if (securePassword == null)
                throw new ArgumentNullException("securePassword");
    
            IntPtr unmanagedString = IntPtr.Zero;
            try
            {
                unmanagedString = Marshal.SecureStringToGlobalAllocUnicode(securePassword);
                return Marshal.PtrToStringUni(unmanagedString);
            }
            finally
            {
                Marshal.ZeroFreeGlobalAllocUnicode(unmanagedString);
            }
        }
    
        /// <summary>
        /// Pass a text password to this function to return a SecureString (doesn't store the password in memory)
        /// </summary>
        /// <param name="password">Text version of a password</param>
        /// <returns>SecureString of a password (not readable by memory)</returns>
        public static SecureString ConvertToSecureString(this string password)
        {
            if (password == null)
                throw new ArgumentNullException("password");
    
            var secure = new SecureString();
            foreach (var c in password.ToCharArray())
                secure.AppendChar(c);
            return secure;
        }
        #endregion
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently discovered metaclasses in python. Basically a metaclass in python is a class
I recently discovered that the java.lang.String.substring method does not return a new string, but
I recently discovered the Emacs code browsing package (ECB) and it seems to be
I recently discovered the fuzzyfinder plugin for vim. It's CoverageFile functionality is perfect, with
I recently discovered the strip_tags() function which takes a string and a list of
We recently discovered that the Google Maps API does not play nicely with SSL.
I recently discovered the genshi.builder module. It reminds me of Divmod Nevow's Stan module.
Having recently discovered this method of development, I'm finding it a rather nice methodology.
I recently discovered Erlang and am now working my way through a couple of
I recently discovered that when you have a page set to session readonly and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.