SecureString 생성자

정의

SecureString 클래스의 새 인스턴스를 초기화합니다.

오버로드

SecureString()

SecureString 클래스의 새 인스턴스를 초기화합니다.

SecureString(Char*, Int32)

Char 개체의 하위 배열에서 SecureString 클래스의 새 인스턴스를 초기화합니다.

이 생성자는 CLS 규격이 아닙니다. CLS 규격 대체 항목은 SecureString()입니다.

SecureString()

SecureString 클래스의 새 인스턴스를 초기화합니다.

public:
 SecureString();
public SecureString ();
Public Sub New ()

예외

이 인스턴스의 값을 보호하거나 보호 해제하는 동안 오류가 발생했습니다.

이 작업이 이 플랫폼에서 지원되지 않습니다.

예제

다음 예제에서는 기본(또는 매개 변수가 없는) 생성자를 사용하여 새 SecureString 개체를 인스턴스화합니다. 그런 다음 AppendChar 메서드를 호출하여 문자 배열을 추가합니다.

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.
using System;
using System.Security;

public class Example
{
   public static void Main()
   {
      // Define the string value to assign to a new secure string.
      char[] chars = { 't', 'e', 's', 't' };
      // Instantiate the secure string.
      SecureString testString = new SecureString();
      // Assign the character array to the secure string.
      foreach (char ch in chars)
         testString.AppendChar(ch);      
      // Display secure string length.
      Console.WriteLine("The length of the string is {0} characters.", 
                        testString.Length);
      testString.Dispose();
   }
}
// The example displays the following output:
//      The length of the string is 4 characters.
Imports System.Security

Module Example
   Public Sub Main()
      ' Define the string value to assign to a new secure string.
      Dim chars() As Char = { "t"c, "e"c, "s"c, "t"c }
      ' Instantiate the secure string.
      Dim testString As SecureString = New SecureString()
      ' Assign the character array to the secure string.
      For Each ch As char In chars
         testString.AppendChar(ch)
      Next         
      ' Display secure string length.
      Console.WriteLine("The length of the string is {0} characters.", _ 
                        testString.Length)
      testString.Dispose()
   End Sub
End Module
' The example displays the following output:
'      The length of the string is 4 characters.

다음 예제에서는 개체의 값을 기반으로 개체를 만듭니다 SecureString String .

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.
using System;
using System.Security;

public class Example
{
   public static void Main()
   {
      // Define the string value to be assigned to the secure string.
      string initString = "TestString";
      // Instantiate the secure string.
      SecureString testString = new SecureString();
      // Use the AppendChar method to add each char value to the secure string.
      foreach (char ch in initString)
         testString.AppendChar(ch);
         
      // Display secure string length.
      Console.WriteLine("The length of the string is {0} characters.", 
                        testString.Length);
      testString.Dispose();
   }
}
// The example displays the following output:
//      The length of the string is 10 characters.
Imports System.Security

Module Example
   Public Sub Main()
      ' Define the string value to be assigned to the secure string.
      Dim initString As String = "TestString"
      ' Instantiate the secure string.
      Dim testString As SecureString = New SecureString()
      ' Use the AppendChar method to add each char value to the secure string.
      For Each ch As Char In initString
         testString.AppendChar(ch)
      Next   
      ' Display secure string length.
      Console.WriteLine("The length of the string is {0} characters.", _ 
                        testString.Length)
      testString.Dispose()
   End Sub
End Module
' The example displays the following output:
'      The length of the string is 10 characters.

적용 대상

SecureString(Char*, Int32)

중요

이 API는 CLS 규격이 아닙니다.

Char 개체의 하위 배열에서 SecureString 클래스의 새 인스턴스를 초기화합니다.

이 생성자는 CLS 규격이 아닙니다. CLS 규격 대체 항목은 SecureString()입니다.

public:
 SecureString(char* value, int length);
[System.CLSCompliant(false)]
public SecureString (char* value, int length);
[System.CLSCompliant(false)]
[System.Security.SecurityCritical]
public SecureString (char* value, int length);
[<System.CLSCompliant(false)>]
new System.Security.SecureString : nativeptr<char> * int -> System.Security.SecureString
[<System.CLSCompliant(false)>]
[<System.Security.SecurityCritical>]
new System.Security.SecureString : nativeptr<char> * int -> System.Security.SecureString

매개 변수

value
Char*

Char 개체의 배열에 대한 포인터입니다.

length
Int32

새 인스턴스에 포함할 value의 요소 수입니다.

특성

예외

value이(가) null인 경우

length가 0보다 작거나 65,536보다 큽니다.

이 보안 문자열 값을 보호하거나 보호 해제하는 동안 오류가 발생했습니다.

이 작업이 이 플랫폼에서 지원되지 않습니다.

예제

다음 예제에서는 SecureString 생성자를 문자 배열에 전달 하 여 새 개체를 인스턴스화합니다.

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.
using System;
using System.Security;

public class Example
{
   unsafe public static void Main()
   {
      SecureString testString;
      // Define the string value to assign to a new secure string.
      char[] chars = { 't', 'e', 's', 't' };

      // Instantiate a new secure string.
      fixed(char* pChars = chars)
      {
         testString = new SecureString(pChars, chars.Length);
      }
      // Display secure string length.
      Console.WriteLine("The length of the string is {0} characters.", 
                        testString.Length);
      testString.Dispose();
   }
}
// The example displays the following output:
//      The length of the string is 4 characters.

설명

이 생성자는 SecureString 에 지정 된의 문자 수로 새 개체를 초기화 value 합니다. length 그러면 인스턴스의 값이 암호화 됩니다.

C #에서이 생성자는 안전 하지 않은 코드의 컨텍스트에서만 정의 됩니다.

적용 대상