SecureString 생성자
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
SecureString 클래스의 새 인스턴스를 초기화합니다.
오버로드
| Name | Description |
|---|---|
| SecureString() |
SecureString 클래스의 새 인스턴스를 초기화합니다. |
| SecureString(Char*, Int32) |
개체의 하위 배열에서 클래스의 SecureString 새 인스턴스를 Char 초기화합니다. 이 생성자는 CLS 규격이 아닙니다. CLS 규격 대안은 .입니다 SecureString(). |
SecureString()
- Source:
- SecureString.cs
- Source:
- SecureString.cs
- Source:
- SecureString.cs
- Source:
- SecureString.cs
- Source:
- SecureString.cs
SecureString 클래스의 새 인스턴스를 초기화합니다.
public:
SecureString();
public SecureString();
Public Sub New ()
예외
이 인스턴스의 값을 보호하거나 보호 해제하는 동안 오류가 발생했습니다.
이 작업은 이 플랫폼에서 지원되지 않습니다.
예제
다음 예제에서는 기본(또는 매개 변수가 없는) 생성자를 사용하여 새 SecureString 개체를 인스턴스화합니다. 그런 다음 메서드를 AppendChar 호출하여 문자 배열을 추가합니다.
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 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)
- Source:
- SecureString.cs
- Source:
- SecureString.cs
- Source:
- SecureString.cs
- Source:
- SecureString.cs
- Source:
- SecureString.cs
Important
이 API는 CLS 규격이 아닙니다.
개체의 하위 배열에서 클래스의 SecureString 새 인스턴스를 Char 초기화합니다.
이 생성자는 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
매개 변수
- length
- Int32
새 인스턴스에 포함할 요소 value 의 수입니다.
- 특성
예외
value은 null입니다.
length 가 0보다 작거나 65,536보다 큽니다.
이 보안 문자열의 값을 보호하거나 보호 해제하는 동안 오류가 발생했습니다.
이 작업은 이 플랫폼에서 지원되지 않습니다.
예제
다음 예제에서는 해당 생성자에 포인터를 문자 배열에 전달하여 새 SecureString 개체를 인스턴스화합니다.
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#에서 이 생성자는 안전하지 않은 코드의 컨텍스트에서만 정의됩니다.