Results 1 to 4 of 4

Thread: [RESOLVED] Using a SecureString

  1. #1

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Resolved [RESOLVED] Using a SecureString

    After you set the contents of a SecureString, how do you extract them?

    I've searched high and low and many people said you can extract the contents, however, it's not well known but none of them stated how to do so. ToString() just return "System.Security.SecureString"

    Any suggestions?
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  2. #2
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    Re: Using a SecureString

    You can get at it using the marshaller:

    Code:
                SecureString password = new SecureString();
                password.AppendChar('x');
                password.AppendChar('y');
                password.AppendChar('z');
    
                IntPtr bstr = Marshal.SecureStringToBSTR(password);
    
                byte b = 1;
                int i = 0;
    
                // Loop through until we hit the string terminator '\0'
                while (((char)b) != '\0')
                {
                    b = Marshal.ReadByte(bstr, i);
                    Console.Write((char)b);
                    i = i + 2;  // BSTR is unicode and occupies 2 bytes
                }
    
                Marshal.ZeroFreeBSTR(bstr);
    Mike

  3. #3
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: [RESOLVED] Using a SecureString

    SecureStrings not all that secure after all then
    I don't live here any more.

  4. #4
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    Re: [RESOLVED] Using a SecureString

    Quote Originally Posted by wossname
    SecureStrings not all that secure after all then
    You're right, they're not 100% secure, but I guess nothing is. SecureString is more secure than a regular string, because they're pinned and encrypted, but effectively they just reduce the exposure and not eliminate it.

    Mike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width