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


RC2CryptoServiceProvider の実装では、40 ビットから 128 ビットのキー長を 8 ビット単位でサポートします。
RC2CryptoServiceProvider オブジェクトは、データの暗号化と復号化を 8 バイトのブロック単位で行うブロック暗号です。最終ブロックのデータが 8 バイト未満の場合、このクラスは不足分のデータを埋め込みます。データが埋め込まれることにより、暗号化されたデータの長さが、元の平文の長さを超える場合があります。

Imports System Imports System.IO Imports System.Text Imports System.Security.Cryptography Module MyMainModule Sub Main() ' Create a new instance of the RC2CryptoServiceProvider class ' and automatically generate a Key and IV. Dim rc2CSP As New RC2CryptoServiceProvider() Console.WriteLine("Effective key size is {0} bits.", rc2CSP.EffectiveKeySize) ' Get the key and IV. Dim key As Byte() = rc2CSP.Key Dim IV As Byte() = rc2CSP.IV ' Get an encryptor. Dim encryptor As ICryptoTransform = rc2CSP.CreateEncryptor(key, IV) ' Encrypt the data as an array of encrypted bytes in memory. Dim msEncrypt As New MemoryStream() Dim csEncrypt As New CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write) ' Convert the data to a byte array. Dim original As String = "Here is some data to encrypt." Dim toEncrypt As Byte() = Encoding.ASCII.GetBytes(original) ' Write all data to the crypto stream and flush it. csEncrypt.Write(toEncrypt, 0, toEncrypt.Length) csEncrypt.FlushFinalBlock() ' Get the encrypted array of bytes. Dim encrypted As Byte() = msEncrypt.ToArray() ''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' This is where the data could be transmitted or saved. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'Get a decryptor that uses the same key and IV as the encryptor. Dim decryptor As ICryptoTransform = rc2CSP.CreateDecryptor(key, IV) ' Now decrypt the previously encrypted message using the decryptor ' obtained in the above step. Dim msDecrypt As New MemoryStream(encrypted) Dim csDecrypt As New CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read) Dim fromEncrypt(toEncrypt.Length) As Byte ' Read the data out of the crypto stream. csDecrypt.Read(fromEncrypt, 0, toEncrypt.Length) ' Convert the byte array back into a string. Dim roundtrip As String = Encoding.ASCII.GetString(fromEncrypt) ' Display the original data and the decrypted data. Console.WriteLine("Original: {0}", original) Console.WriteLine("Round Trip: {0}", roundtrip) Console.ReadLine() End Sub End Module
using System; using System.IO; using System.Text; using System.Security.Cryptography; namespace RC2CryptoServiceProvider_Examples { class MyMainClass { public static void Main() { // Create a new instance of the RC2CryptoServiceProvider class // and automatically generate a Key and IV. RC2CryptoServiceProvider rc2CSP = new RC2CryptoServiceProvider(); Console.WriteLine("Effective key size is {0} bits.", rc2CSP.EffectiveKeySize); // Get the key and IV. byte[] key = rc2CSP.Key; byte[] IV = rc2CSP.IV; // Get an encryptor. ICryptoTransform encryptor = rc2CSP.CreateEncryptor(key, IV); // Encrypt the data as an array of encrypted bytes in memory. MemoryStream msEncrypt = new MemoryStream(); CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write); // Convert the data to a byte array. string original = "Here is some data to encrypt."; byte[] toEncrypt = Encoding.ASCII.GetBytes(original); // Write all data to the crypto stream and flush it. csEncrypt.Write(toEncrypt, 0, toEncrypt.Length); csEncrypt.FlushFinalBlock(); // Get the encrypted array of bytes. byte[] encrypted = msEncrypt.ToArray(); /////////////////////////////////////////////////////// // This is where the data could be transmitted or saved. /////////////////////////////////////////////////////// //Get a decryptor that uses the same key and IV as the encryptor. ICryptoTransform decryptor = rc2CSP.CreateDecryptor(key, IV); // Now decrypt the previously encrypted message using the decryptor // obtained in the above step. MemoryStream msDecrypt = new MemoryStream(encrypted); CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read); byte[] fromEncrypt = new byte[toEncrypt.Length]; // Read the data out of the crypto stream. csDecrypt.Read(fromEncrypt, 0, toEncrypt.Length); // Convert the byte array back into a string. String roundtrip = Encoding.ASCII.GetString(fromEncrypt); // Display the original data and the decrypted data. Console.WriteLine("Original: {0}", original); Console.WriteLine("Round Trip: {0}", roundtrip); Console.ReadLine(); } } }

System.Security.Cryptography.SymmetricAlgorithm
System.Security.Cryptography.RC2
System.Security.Cryptography.RC2CryptoServiceProvider


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


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



Imports System Imports System.IO Imports System.Text Imports System.Security.Cryptography Module MyMainModule Sub Main() ' Create a new instance of the RC2CryptoServiceProvider class ' and automatically generate a Key and IV. Dim rc2CSP As New RC2CryptoServiceProvider() Console.WriteLine("Effective key size is {0} bits.", rc2CSP.EffectiveKeySize) ' Get the key and IV. Dim key As Byte() = rc2CSP.Key Dim IV As Byte() = rc2CSP.IV ' Get an encryptor. Dim encryptor As ICryptoTransform = rc2CSP.CreateEncryptor(key, IV) ' Encrypt the data as an array of encrypted bytes in memory. Dim msEncrypt As New MemoryStream() Dim csEncrypt As New CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write) ' Convert the data to a byte array. Dim original As String = "Here is some data to encrypt." Dim toEncrypt As Byte() = Encoding.ASCII.GetBytes(original) ' Write all data to the crypto stream and flush it. csEncrypt.Write(toEncrypt, 0, toEncrypt.Length) csEncrypt.FlushFinalBlock() ' Get the encrypted array of bytes. Dim encrypted As Byte() = msEncrypt.ToArray() ''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' This is where the data could be transmitted or saved. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'Get a decryptor that uses the same key and IV as the encryptor. Dim decryptor As ICryptoTransform = rc2CSP.CreateDecryptor(key, IV) ' Now decrypt the previously encrypted message using the decryptor ' obtained in the above step. Dim msDecrypt As New MemoryStream(encrypted) Dim csDecrypt As New CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read) Dim fromEncrypt(toEncrypt.Length) As Byte ' Read the data out of the crypto stream. csDecrypt.Read(fromEncrypt, 0, toEncrypt.Length) ' Convert the byte array back into a string. Dim roundtrip As String = Encoding.ASCII.GetString(fromEncrypt) ' Display the original data and the decrypted data. Console.WriteLine("Original: {0}", original) Console.WriteLine("Round Trip: {0}", roundtrip) Console.ReadLine() End Sub End Module
using System; using System.IO; using System.Text; using System.Security.Cryptography; namespace RC2CryptoServiceProvider_Examples { class MyMainClass { public static void Main() { // Create a new instance of the RC2CryptoServiceProvider class // and automatically generate a Key and IV. RC2CryptoServiceProvider rc2CSP = new RC2CryptoServiceProvider(); Console.WriteLine("Effective key size is {0} bits.", rc2CSP.EffectiveKeySize); // Get the key and IV. byte[] key = rc2CSP.Key; byte[] IV = rc2CSP.IV; // Get an encryptor. ICryptoTransform encryptor = rc2CSP.CreateEncryptor(key, IV); // Encrypt the data as an array of encrypted bytes in memory. MemoryStream msEncrypt = new MemoryStream(); CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write); // Convert the data to a byte array. string original = "Here is some data to encrypt."; byte[] toEncrypt = Encoding.ASCII.GetBytes(original); // Write all data to the crypto stream and flush it. csEncrypt.Write(toEncrypt, 0, toEncrypt.Length); csEncrypt.FlushFinalBlock(); // Get the encrypted array of bytes. byte[] encrypted = msEncrypt.ToArray(); /////////////////////////////////////////////////////// // This is where the data could be transmitted or saved. /////////////////////////////////////////////////////// //Get a decryptor that uses the same key and IV as the encryptor. ICryptoTransform decryptor = rc2CSP.CreateDecryptor(key, IV); // Now decrypt the previously encrypted message using the decryptor // obtained in the above step. MemoryStream msDecrypt = new MemoryStream(encrypted); CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read); byte[] fromEncrypt = new byte[toEncrypt.Length]; // Read the data out of the crypto stream. csDecrypt.Read(fromEncrypt, 0, toEncrypt.Length); // Convert the byte array back into a string. String roundtrip = Encoding.ASCII.GetString(fromEncrypt); // Display the original data and the decrypted data. Console.WriteLine("Original: {0}", original); Console.WriteLine("Round Trip: {0}", roundtrip); Console.ReadLine(); } } }

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


RC2CryptoServiceProvider プロパティ

名前 | 説明 | |
---|---|---|
![]() | BlockSize | 暗号操作のブロック サイズをビット単位で取得または設定します。 ( SymmetricAlgorithm から継承されます。) |
![]() | EffectiveKeySize | オーバーライドされます。 RC2 アルゴリズムで使用する共有キーの有効サイズを、ビット単位で取得または設定します。 |
![]() | FeedbackSize | 暗号操作のフィードバック サイズをビット単位で取得または設定します。 ( SymmetricAlgorithm から継承されます。) |
![]() | IV | 対称アルゴリズムの初期化ベクタ (IV) を取得または設定します。 ( SymmetricAlgorithm から継承されます。) |
![]() | Key | 対称アルゴリズムの共有キーを取得または設定します。 ( SymmetricAlgorithm から継承されます。) |
![]() | KeySize | RC2 アルゴリズムで使用する共有キーのサイズをビット単位で取得または設定します。 ( RC2 から継承されます。) |
![]() | LegalBlockSizes | 対称アルゴリズムでサポートされているブロック サイズを取得します。 ( SymmetricAlgorithm から継承されます。) |
![]() | LegalKeySizes | 対称アルゴリズムでサポートされているキー サイズを取得します。 ( SymmetricAlgorithm から継承されます。) |
![]() | Mode | 対称アルゴリズムの操作モードを取得または設定します。 ( SymmetricAlgorithm から継承されます。) |
![]() | Padding | 対称アルゴリズムで使用する埋め込みモードを取得または設定します。 ( SymmetricAlgorithm から継承されます。) |
![]() | UseSalt | 11 バイト長、値 0 の salt を使用してキーを作成するかどうかを指定する値を取得または設定します。 |

RC2CryptoServiceProvider メソッド

名前 | 説明 | |
---|---|---|
![]() | Clear | SymmetricAlgorithm クラスによって使用されているすべてのリソースを解放します。 ( SymmetricAlgorithm から継承されます。) |
![]() | Create | オーバーロードされます。 暗号オブジェクトのインスタンスを作成し、RC2 アルゴリズムを実行します。 ( RC2 から継承されます。) |
![]() | CreateDecryptor | オーバーロードされます。 対称 RC2 復号化オブジェクトを作成します。 |
![]() | CreateEncryptor | オーバーロードされます。 対称 RC2 暗号化オブジェクトを作成します。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GenerateIV | オーバーライドされます。 アルゴリズムに使用するランダムな初期化ベクタ (IV) を生成します。 |
![]() | GenerateKey | オーバーライドされます。 アルゴリズムで使用するランダム キー (Key) を生成します。 |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |
![]() | ValidKeySize | 指定されたキー サイズが、現在のアルゴリズムに対して有効かどうかを判断します。 ( SymmetricAlgorithm から継承されます。) |

RC2CryptoServiceProvider メンバ
RC2 アルゴリズムの暗号サービス プロバイダ (CSP : Cryptographic Service Provider) 実装にアクセスするためのラッパー オブジェクトを定義します。このクラスは継承できません。
RC2CryptoServiceProvider データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | BlockSize | 暗号操作のブロック サイズをビット単位で取得または設定します。(SymmetricAlgorithm から継承されます。) |
![]() | EffectiveKeySize | オーバーライドされます。 RC2 アルゴリズムで使用する共有キーの有効サイズを、ビット単位で取得または設定します。 |
![]() | FeedbackSize | 暗号操作のフィードバック サイズをビット単位で取得または設定します。(SymmetricAlgorithm から継承されます。) |
![]() | IV | 対称アルゴリズムの初期化ベクタ (IV) を取得または設定します。(SymmetricAlgorithm から継承されます。) |
![]() | Key | 対称アルゴリズムの共有キーを取得または設定します。(SymmetricAlgorithm から継承されます。) |
![]() | KeySize | RC2 アルゴリズムで使用する共有キーのサイズをビット単位で取得または設定します。(RC2 から継承されます。) |
![]() | LegalBlockSizes | 対称アルゴリズムでサポートされているブロック サイズを取得します。(SymmetricAlgorithm から継承されます。) |
![]() | LegalKeySizes | 対称アルゴリズムでサポートされているキー サイズを取得します。(SymmetricAlgorithm から継承されます。) |
![]() | Mode | 対称アルゴリズムの操作モードを取得または設定します。(SymmetricAlgorithm から継承されます。) |
![]() | Padding | 対称アルゴリズムで使用する埋め込みモードを取得または設定します。(SymmetricAlgorithm から継承されます。) |
![]() | UseSalt | 11 バイト長、値 0 の salt を使用してキーを作成するかどうかを指定する値を取得または設定します。 |

名前 | 説明 | |
---|---|---|
![]() | Clear | SymmetricAlgorithm クラスによって使用されているすべてのリソースを解放します。 (SymmetricAlgorithm から継承されます。) |
![]() | Create | オーバーロードされます。 暗号オブジェクトのインスタンスを作成し、RC2 アルゴリズムを実行します。 (RC2 から継承されます。) |
![]() | CreateDecryptor | オーバーロードされます。 対称 RC2 復号化オブジェクトを作成します。 |
![]() | CreateEncryptor | オーバーロードされます。 対称 RC2 暗号化オブジェクトを作成します。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GenerateIV | オーバーライドされます。 アルゴリズムに使用するランダムな初期化ベクタ (IV) を生成します。 |
![]() | GenerateKey | オーバーライドされます。 アルゴリズムで使用するランダム キー (Key) を生成します。 |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |
![]() | ValidKeySize | 指定されたキー サイズが、現在のアルゴリズムに対して有効かどうかを判断します。 (SymmetricAlgorithm から継承されます。) |

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

- RC2CryptoServiceProviderのページへのリンク