SecureString クラス
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
不要になったときにコンピューターのメモリから削除するなどして機密を保持する必要があるテキストを表します。 このクラスは継承できません。
public ref class SecureString sealed : IDisposable
public sealed class SecureString : IDisposable
type SecureString = class
interface IDisposable
Public NotInheritable Class SecureString
Implements IDisposable
- 継承
-
SecureString
- 実装
次の例では、 を使用 SecureString してユーザーのパスワードをセキュリティで保護し、新しいプロセスを開始するための資格情報として使用する方法を示します。
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Security;
public class Example
{
public static void Main()
{
// Instantiate the secure string.
SecureString securePwd = new SecureString();
ConsoleKeyInfo key;
Console.Write("Enter password: ");
do {
key = Console.ReadKey(true);
// Ignore any key out of range.
if (((int) key.Key) >= 65 && ((int) key.Key <= 90)) {
// Append the character to the password.
securePwd.AppendChar(key.KeyChar);
Console.Write("*");
}
// Exit if Enter key is pressed.
} while (key.Key != ConsoleKey.Enter);
Console.WriteLine();
try {
Process.Start("Notepad.exe", "MyUser", securePwd, "MYDOMAIN");
}
catch (Win32Exception e) {
Console.WriteLine(e.Message);
}
finally {
securePwd.Dispose();
}
}
}
Imports System.ComponentModel
Imports System.Diagnostics
Imports System.Security
Public Class Example
Public Shared Sub Main()
' Instantiate the secure string.
Dim securePwd As New SecureString()
Dim key As ConsoleKeyInfo
Console.Write("Enter password: ")
Do
key = Console.ReadKey(True)
' Ignore any key out of range
If CInt(key.Key) >= 65 And CInt(key.Key <= 90) Then
' Append the character to the password.
securePwd.AppendChar(key.KeyChar)
Console.Write("*")
End If
' Exit if Enter key is pressed.
Loop While key.Key <> ConsoleKey.Enter
Console.WriteLine()
Try
Process.Start("Notepad.exe", "MyUser", securePwd, "MYDOMAIN")
Catch e As Win32Exception
Console.WriteLine(e.Message)
Finally
securePwd.Dispose()
End Try
End Sub
End Class
この API の詳細については、「 SecureString の補足 API 解説」を参照してください。
Secure |
SecureString クラスの新しいインスタンスを初期化します。 |
Secure |
Char オブジェクトのサブ配列から SecureString クラスの新しいインスタンスを初期化します。 このコンストラクターは、CLS 準拠ではありません。 CLS 準拠の代わりとして SecureString() を使用できます。 |
Length |
現在のセキュリティ文字列内の文字数を取得します。 |
Append |
現在のセキュリティ文字列の末尾に、文字を 1 つ追加します。 |
Clear() |
現在のセキュリティ文字列の値を削除します。 |
Copy() |
現在のセキュリティ文字列のコピーを作成します。 |
Dispose() |
現在の SecureString オブジェクトによって使用されているすべてのリソースを解放します。 |
Equals(Object) |
指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。 (継承元 Object) |
Get |
既定のハッシュ関数として機能します。 (継承元 Object) |
Get |
現在のインスタンスの Type を取得します。 (継承元 Object) |
Insert |
このセキュリティ文字列の指定したインデックス位置に文字を挿入します。 |
Is |
このセキュリティ文字列が読み取り専用としてマークされているかどうかを示します。 |
Make |
このセキュリティ文字列のテキスト値を読み取り専用にします。 |
Memberwise |
現在の Object の簡易コピーを作成します。 (継承元 Object) |
Remove |
このセキュリティ文字列の指定されたインデックス位置にある文字を削除します。 |
Set |
指定されたインデックス位置にある既存の文字を別の文字に置き換えます。 |
To |
現在のオブジェクトを表す文字列を返します。 (継承元 Object) |
製品 | バージョン |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。