SecureString Oluşturucular

Tanım

SecureString sınıfının yeni bir örneğini başlatır.

Aşırı Yüklemeler

Name Description
SecureString()

SecureString sınıfının yeni bir örneğini başlatır.

SecureString(Char*, Int32)

Nesnelerin alt dizisinden sınıfının yeni bir örneğini SecureStringChar başlatır.

Bu oluşturucu CLS uyumlu değil. CLS uyumlu alternatif SecureString().

SecureString()

Kaynak:
SecureString.cs
Kaynak:
SecureString.cs
Kaynak:
SecureString.cs
Kaynak:
SecureString.cs
Kaynak:
SecureString.cs

SecureString sınıfının yeni bir örneğini başlatır.

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

Özel durumlar

Bu örneğin değeri korunurken veya koruması kaldırılırken bir hata oluştu.

Bu işlem bu platformda desteklenmiyor.

Örnekler

Aşağıdaki örnek, yeni SecureString bir nesne örneği oluşturmak için varsayılan (veya parametresiz) oluşturucuyu kullanır. Ardından bir karakter dizisi eklemek için yöntemini çağırır 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.

Aşağıdaki örnek, bir SecureString nesnenin değerinden bir String nesne oluşturur.

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.

Şunlara uygulanır

SecureString(Char*, Int32)

Kaynak:
SecureString.cs
Kaynak:
SecureString.cs
Kaynak:
SecureString.cs
Kaynak:
SecureString.cs
Kaynak:
SecureString.cs

Önemli

Bu API, CLS uyumlu değildir.

Nesnelerin alt dizisinden sınıfının yeni bir örneğini SecureStringChar başlatır.

Bu oluşturucu CLS uyumlu değil. CLS uyumlu alternatif 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

Parametreler

value
Char*

Bir nesne dizisi işaretçisi Char .

length
Int32

Öğesinin yeni örneğe eklenecek öğe value sayısı.

Öznitelikler

Özel durumlar

value, null'e eşittir.

length sıfırdan küçük veya 65.536'dan büyük.

Bu güvenli dizenin değeri korunurken veya koruması kaldırılırken bir hata oluştu.

Bu işlem bu platformda desteklenmiyor.

Örnekler

Aşağıdaki örnek, oluşturucusunu bir karakter dizisine işaretçi geçirerek yeni SecureString bir nesne örneği oluşturur.

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.

Açıklamalar

Bu oluşturucu yeni SecureString nesneyi tarafından valuebelirtilen karakter length sayısına başlatır; örneğin değeri daha sonra şifrelenir.

C# dilinde bu oluşturucu yalnızca güvenli olmayan kod bağlamında tanımlanır.

Şunlara uygulanır