SecureString Constructor ()
.NET Framework (current version)
Initializes a new instance of the SecureString class.
Assembly: mscorlib (in mscorlib.dll)
| Exception | Condition |
|---|---|
| CryptographicException | An error occurred while protecting or unprotecting the value of this instance. |
| NotSupportedException | This operation is not supported on this platform. |
SecureString is only supported on Windows 2000 Service Pack 3 and later.
The following example uses the default (or parameterless) constructor to instantiate a new SecureString object. It then calls the AppendChar method to add an array of characters to it.
using namespace System; using namespace System::Security; int main(array<System::String ^> ^args) { // Define the string value to assign to a new secure string. Char chars[4] = { 't', 'e', 's', 't' }; // Instantiate the secure string. SecureString^ testString = gcnew SecureString(); // Assign the character array to the secure string. for each (Char ch in chars) { testString->AppendChar(ch); } // Display secure string length. Console::WriteLine("The length of the string is {0} characters.", testString->Length); delete testString; return 0; } // The example displays the following output: // The length of the string is 4 characters.
The following example creates a SecureString object from the value of a String object.
using namespace System; using namespace System::Security; int main(array<System::String ^> ^args) { // Define the string value to be assigned to the secure string. String^ initString = "TestString"; // Instantiate the secure string. SecureString^ testString = gcnew SecureString(); // Assign the character array to the secure string. for each (Char ch in initString) { testString->AppendChar(ch); } // Display secure string length. Console::WriteLine("The length of the string is {0} characters.", testString->Length); delete testString; return 0; } // The example displays the following output: // The length of the string is 10 characters.
.NET Framework
Available since 2.0
Available since 2.0
Show: