Export (0) Print
Expand All
3 out of 13 rated this helpful - Rate this topic

SecureString Class

Represents text that should be kept confidential. The text is encrypted for privacy when being used, and deleted from computer memory when no longer needed. This class cannot be inherited.

System.Object
  System.Security.SecureString

Namespace:  System.Security
Assembly:  mscorlib (in mscorlib.dll)
[<Sealed>]
type SecureString =  
    class 
        interface IDisposable 
    end

The SecureString type exposes the following members.

  NameDescription
Public methodSecureString()Initializes a new instance of the SecureString class.
Public methodSecureString(Char*, Int32)Infrastructure. Initializes a new instance of the SecureString class from a subarray of System.Char objects.
Top
  NameDescription
Public propertyLengthGets the number of characters in the current secure string.
Top
  NameDescription
Public methodAppendCharAppends a character to the end of the current secure string.
Public methodClearDeletes the value of the current secure string.
Public methodCopyCreates a copy of the current secure string.
Public methodDisposeReleases all resources used by the current SecureString object.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInsertAtInserts a character in this secure string at the specified index position.
Public methodIsReadOnlyIndicates whether this secure string is marked read-only.
Public methodMakeReadOnlyMakes the text value of this secure string read-only.
Public methodRemoveAtRemoves the character at the specified index position from this secure string.
Public methodSetAtReplaces the existing character at the specified index position with another character.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

An instance of the System.String class is both immutable and, when no longer needed, cannot be programmatically scheduled for garbage collection; that is, the instance is read-only after it is created and it is not possible to predict when the instance will be deleted from computer memory. Consequently, if a String object contains sensitive information such as a password, credit card number, or personal data, there is a risk the information could be revealed after it is used because your application cannot delete the data from computer memory.

Important noteImportant

This type implements the IDisposable interface. When you have finished using the type, you should dispose of it either directly or indirectly. To dispose of the type directly, call its Dispose method in a try/catch block. To dispose of it indirectly, use a language construct such as using (in C#) or Using (in Visual Basic). For more information, see the “Using an Object that Implements IDisposable” section in the IDisposable interface topic.

A SecureString object is similar to a String object in that it has a text value. However, the value of a SecureString object is automatically encrypted, can be modified until your application marks it as read-only, and can be deleted from computer memory by either your application or the .NET Framework garbage collector.

The value of an instance of SecureString is automatically encrypted when the instance is initialized or when the value is modified. Your application can render the instance immutable and prevent further modification by invoking the MakeReadOnly method.

Note that SecureString has no members that inspect, compare, or convert the value of a SecureString. The absence of such members helps protect the value of the instance from accidental or malicious exposure. Use appropriate members of the System.Runtime.InteropServices.Marshal class, such as the SecureStringToBSTR method, to manipulate the value of a SecureString object.

The SecureString class and its members are not visible to COM. For more information, see ComVisibleAttribute.

Windows 2000 Platform Note: In addition to Windows 2000 Service Pack 4 and later, SecureString is supported on Windows 2000 Service Pack 3.

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition Platform Note: The SecureString class is not supported on Windows 98 or Windows Millennium Edition.

The following example demonstrates how to use a SecureString to secure a user’s password for use as a credential to start a new process.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.