RNGCryptoServiceProvider クラス
アセンブリ: mscorlib (mscorlib.dll 内)

<ComVisibleAttribute(True)> _ Public NotInheritable Class RNGCryptoServiceProvider Inherits RandomNumberGenerator
[ComVisibleAttribute(true)] public ref class RNGCryptoServiceProvider sealed : public RandomNumberGenerator

RNGCryptoServiceProvider クラスを使用して乱数を作成する方法を次のコード例に示します。
'The following sample uses the Cryptography class to simulate the roll of a dice. Imports System Imports System.IO Imports System.Text Imports System.Security.Cryptography Class RNGCSP ' Main method. Public Shared Sub Main() ' Roll the dice 30 times and display ' the results to the console. Dim x As Integer For x = 0 To 30 Console.WriteLine(RollDice(6)) Next x End Sub 'Main ' This method simulates a roll of the dice. The input parameter is the ' number of sides of the dice. Public Shared Function RollDice(NumSides As Integer) As Integer ' Create a byte array to hold the random value. Dim randomNumber(0) As Byte ' Create a new instance of the RNGCryptoServiceProvider. Dim Gen As New RNGCryptoServiceProvider() ' Fill the array with a random value. Gen.GetBytes(randomNumber) ' Convert the byte to an integer value to make the modulus operation easier. Dim rand As Integer = Convert.ToInt32(randomNumber(0)) ' Return the random number mod the number ' of sides. The possible values are zero- ' based, so we add one. Return rand Mod NumSides + 1 End Function 'RollDice End Class 'CryptoMemoryStream
//The following sample uses the Cryptography class to simulate the roll of a dice. using System; using System.IO; using System.Text; using System.Security.Cryptography; class RNGCSP { // Main method. public static void Main() { // Roll the dice 30 times and display // the results to the console. for(int x = 0; x <= 30; x++) Console.WriteLine(RollDice(6)); } // This method simulates a roll of the dice. The input parameter is the // number of sides of the dice. public static int RollDice(int NumSides) { // Create a byte array to hold the random value. byte[] randomNumber = new byte[1]; // Create a new instance of the RNGCryptoServiceProvider. RNGCryptoServiceProvider Gen = new RNGCryptoServiceProvider(); // Fill the array with a random value. Gen.GetBytes(randomNumber); // Convert the byte to an integer value to make the modulus operation easier. int rand = Convert.ToInt32(randomNumber[0]); // Return the random number mod the number // of sides. The possible values are zero- // based, so we add one. return rand % NumSides + 1; } }
// The following sample uses the Cryptography class // to simulate the roll of a dice. using namespace System; using namespace System::IO; using namespace System::Text; using namespace System::Security::Cryptography; int RollDice(int numberSides) { // Create a byte array to hold the random value. array<Byte>^ randomNumber = gcnew array<Byte>(1); // Create a new instance of the RNGCryptoServiceProvider. RNGCryptoServiceProvider^ cryptoProvider = gcnew RNGCryptoServiceProvider(); // Fill the array with a random value. cryptoProvider->GetBytes(randomNumber); // Convert the byte to an integer value to make the modulus operation // easier. int rand = Convert::ToInt32(randomNumber[0]); // Return the random number mod the number of sides. The possible // values are zero-based, so we add one. return (rand % numberSides) + 1; } int main() { // Roll the dice 30 times and display // the results to the console. for (int i = 0; i <= 30; i++) { Console::WriteLine(RollDice(6)); } }

System.Security.Cryptography.RandomNumberGenerator
System.Security.Cryptography.RNGCryptoServiceProvider


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


RNGCryptoServiceProvider コンストラクタ ()
アセンブリ: mscorlib (mscorlib.dll 内)


RNGCryptoServiceProvider クラスを使用して乱数を作成する方法を次のコード例に示します。
'The following sample uses the Cryptography class to simulate the roll of a dice. Imports System Imports System.IO Imports System.Text Imports System.Security.Cryptography Class RNGCSP ' Main method. Public Shared Sub Main() ' Roll the dice 30 times and display ' the results to the console. Dim x As Integer For x = 0 To 30 Console.WriteLine(RollDice(6)) Next x End Sub 'Main ' This method simulates a roll of the dice. The input parameter is the ' number of sides of the dice. Public Shared Function RollDice(NumSides As Integer) As Integer ' Create a byte array to hold the random value. Dim randomNumber(0) As Byte ' Create a new instance of the RNGCryptoServiceProvider. Dim Gen As New RNGCryptoServiceProvider() ' Fill the array with a random value. Gen.GetBytes(randomNumber) ' Convert the byte to an integer value to make the modulus operation easier. Dim rand As Integer = Convert.ToInt32(randomNumber(0)) ' Return the random number mod the number ' of sides. The possible values are zero- ' based, so we add one. Return rand Mod NumSides + 1 End Function 'RollDice End Class 'CryptoMemoryStream
//The following sample uses the Cryptography class to simulate the roll of a dice. using System; using System.IO; using System.Text; using System.Security.Cryptography; class RNGCSP { // Main method. public static void Main() { // Roll the dice 30 times and display // the results to the console. for(int x = 0; x <= 30; x++) Console.WriteLine(RollDice(6)); } // This method simulates a roll of the dice. The input parameter is the // number of sides of the dice. public static int RollDice(int NumSides) { // Create a byte array to hold the random value. byte[] randomNumber = new byte[1]; // Create a new instance of the RNGCryptoServiceProvider. RNGCryptoServiceProvider Gen = new RNGCryptoServiceProvider(); // Fill the array with a random value. Gen.GetBytes(randomNumber); // Convert the byte to an integer value to make the modulus operation easier. int rand = Convert.ToInt32(randomNumber[0]); // Return the random number mod the number // of sides. The possible values are zero- // based, so we add one. return rand % NumSides + 1; } }
// The following sample uses the Cryptography class // to simulate the roll of a dice. using namespace System; using namespace System::IO; using namespace System::Text; using namespace System::Security::Cryptography; int RollDice(int numberSides) { // Create a byte array to hold the random value. array<Byte>^ randomNumber = gcnew array<Byte>(1); // Create a new instance of the RNGCryptoServiceProvider. RNGCryptoServiceProvider^ cryptoProvider = gcnew RNGCryptoServiceProvider(); // Fill the array with a random value. cryptoProvider->GetBytes(randomNumber); // Convert the byte to an integer value to make the modulus operation // easier. int rand = Convert::ToInt32(randomNumber[0]); // Return the random number mod the number of sides. The possible // values are zero-based, so we add one. return (rand % numberSides) + 1; } int main() { // Roll the dice 30 times and display // the results to the console. for (int i = 0; i <= 30; i++) { Console::WriteLine(RollDice(6)); } }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


RNGCryptoServiceProvider コンストラクタ (CspParameters)
アセンブリ: mscorlib (mscorlib.dll 内)

- cspParams
暗号化サービス プロバイダ (CSP) に渡すパラメータ。

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


RNGCryptoServiceProvider コンストラクタ (Byte[])
アセンブリ: mscorlib (mscorlib.dll 内)


このメソッドでは、RNGCryptoServiceProvider クラスは直接初期化されません。このメソッドを呼び出すことは、RNGCryptoServiceProvider コンストラクタを呼び出して null 参照 (Visual Basic では Nothing) を渡すことと同じです。

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


RNGCryptoServiceProvider コンストラクタ

名前 | 説明 |
---|---|
RNGCryptoServiceProvider () | RNGCryptoServiceProvider クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
RNGCryptoServiceProvider (Byte[]) | RNGCryptoServiceProvider クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
RNGCryptoServiceProvider (CspParameters) | 指定したパラメータを使用して、RNGCryptoServiceProvider クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
RNGCryptoServiceProvider (String) | RNGCryptoServiceProvider クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |

RNGCryptoServiceProvider コンストラクタ (String)
アセンブリ: mscorlib (mscorlib.dll 内)


このメソッドでは、RNGCryptoServiceProvider クラスは直接初期化されません。このメソッドを呼び出すことは、RNGCryptoServiceProvider コンストラクタを呼び出して null 参照 (Visual Basic では Nothing) を渡すことと同じです。

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


RNGCryptoServiceProvider メソッド

名前 | 説明 | |
---|---|---|
![]() | Create | オーバーロードされます。 暗号乱数ジェネレータの実装のインスタンスを作成します。 ( RandomNumberGenerator から継承されます。) |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetBytes | オーバーライドされます。 バイト配列に、暗号化に使用するランダムな値の厳密なシーケンスを設定します。 |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetNonZeroBytes | オーバーライドされます。 バイト配列に、暗号化に使用するランダムな 0 以外の値の厳密なシーケンスを設定します。 |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |


RNGCryptoServiceProvider メンバ
暗号サービス プロバイダ (CSP : Cryptographic Service Provider) によって提供された実装を使用して、暗号乱数ジェネレータ (RNG : Random Number Generator) を実装します。このクラスは継承できません。
RNGCryptoServiceProvider データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | Create | オーバーロードされます。 暗号乱数ジェネレータの実装のインスタンスを作成します。 (RandomNumberGenerator から継承されます。) |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetBytes | オーバーライドされます。 バイト配列に、暗号化に使用するランダムな値の厳密なシーケンスを設定します。 |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetNonZeroBytes | オーバーライドされます。 バイト配列に、暗号化に使用するランダムな 0 以外の値の厳密なシーケンスを設定します。 |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |


Weblioに収録されているすべての辞書からRNGCryptoServiceProviderを検索する場合は、下記のリンクをクリックしてください。

- RNGCryptoServiceProviderのページへのリンク