SecureString Konstruktorok
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Inicializálja a SecureString osztály új példányát.
Túlterhelések
| Name | Description |
|---|---|
| SecureString() |
Inicializálja a SecureString osztály új példányát. |
| SecureString(Char*, Int32) |
Inicializálja az osztály új példányát az SecureString objektumok egy alarrájából Char . Ez a konstruktor nem CLS-kompatibilis. A CLS-kompatibilis alternatíva a SecureString(). |
SecureString()
- Forrás:
- SecureString.cs
- Forrás:
- SecureString.cs
- Forrás:
- SecureString.cs
- Forrás:
- SecureString.cs
- Forrás:
- SecureString.cs
Inicializálja a SecureString osztály új példányát.
public:
SecureString();
public SecureString();
Public Sub New ()
Kivételek
Hiba történt a példány értékének védelme vagy megszüntetése során.
Ez a művelet ezen a platformon nem támogatott.
Példák
Az alábbi példa az alapértelmezett (vagy paraméter nélküli) konstruktort használja egy új SecureString objektum példányosításához. Ezután meghívja a AppendChar metódust, hogy adjon hozzá egy karaktertömböt.
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.
Az alábbi példa objektumot SecureString hoz létre egy String objektum értékéből.
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.
A következőre érvényes:
SecureString(Char*, Int32)
- Forrás:
- SecureString.cs
- Forrás:
- SecureString.cs
- Forrás:
- SecureString.cs
- Forrás:
- SecureString.cs
- Forrás:
- SecureString.cs
Fontos
Ez az API nem CLS-kompatibilis.
Inicializálja az osztály új példányát az SecureString objektumok egy alarrájából Char .
Ez a konstruktor nem CLS-kompatibilis. A CLS-kompatibilis alternatíva a 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
Paraméterek
- length
- Int32
Az új példányba felvenni kívánt elemek value száma.
- Attribútumok
Kivételek
value az null.
length kisebb, mint nulla vagy nagyobb, mint 65 536.
Hiba történt a biztonságos sztring értékének védelme vagy feloldása során.
Ez a művelet ezen a platformon nem támogatott.
Példák
Az alábbi példa egy új SecureString objektum példányosítását mutatja be úgy, hogy a konstruktor egy mutatót ad át egy karaktertömbnek.
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.
Megjegyzések
Ez a konstruktor inicializálja az új SecureString objektumot a megadott valueszámú karakterrelength; a példány értéke ezután titkosítva lesz.
A C#-ban ez a konstruktor csak a nem biztonságos kód kontextusában van definiálva.