SecureString Constructor (Char*, Int32)
This API supports the product infrastructure and is not intended to be used directly from your code.
Initializes a new instance of the SecureString class from a subarray of System::Char objects.
This constructor is not CLS-compliant. The CLS-compliant alternative is SecureString::SecureString().
This API is not CLS-compliant.
Assembly: mscorlib (in mscorlib.dll)
public: [SecurityCriticalAttribute] [CLSCompliantAttribute(false)] SecureString( wchar_t* value, int length )
Parameters
- value
-
Type:
System::Char*
A pointer to an array of System::Char objects.
- length
-
Type:
System::Int32
The number of elements of value to include in the new instance.
| Exception | Condition |
|---|---|
| ArgumentNullException | value is null. |
| ArgumentOutOfRangeException | length is less than zero or greater than 65,536. |
| CryptographicException | An error occurred while protecting or unprotecting the value of this secure string. |
| NotSupportedException | This operation is not supported on this platform. |
This constructor initializes the new SecureString object to the number of characters in value specified by length; the value of the instance is then encrypted.
In C#, this constructor is defined only in the context of unsafe code.
SecureString is only supported on Windows 2000 Service Pack 3 and later.
The following example instantiates a new SecureString object by passing its constructor a pointer to a character array.
using namespace System; using namespace System::Security; int main(array<System::String ^> ^args) { SecureString^ testString; // Define the string value to assign to a new secure string. Char chars[4] = { 't', 'e', 's', 't' }; // Instantiate a new secure string. Char* pChars = &chars[0]; testString = gcnew SecureString(pChars, sizeof(chars)/sizeof(chars[0])); // 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.
requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.
Available since 2.0