RC2CryptoServiceProvider クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
注意事項
Derived cryptographic types are obsolete. Use the Create method on the base type instead.
RC2 アルゴリズムの暗号化サービス プロバイダー (CSP) 実装にアクセスするためのラッパー オブジェクトを定義します。 このクラスは継承できません。
public ref class RC2CryptoServiceProvider sealed : System::Security::Cryptography::RC2
[System.Obsolete("Derived cryptographic types are obsolete. Use the Create method on the base type instead.", DiagnosticId="SYSLIB0021", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public sealed class RC2CryptoServiceProvider : System.Security.Cryptography.RC2
public sealed class RC2CryptoServiceProvider : System.Security.Cryptography.RC2
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class RC2CryptoServiceProvider : System.Security.Cryptography.RC2
[<System.Obsolete("Derived cryptographic types are obsolete. Use the Create method on the base type instead.", DiagnosticId="SYSLIB0021", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
type RC2CryptoServiceProvider = class
inherit RC2
type RC2CryptoServiceProvider = class
inherit RC2
[<System.Runtime.InteropServices.ComVisible(true)>]
type RC2CryptoServiceProvider = class
inherit RC2
Public NotInheritable Class RC2CryptoServiceProvider
Inherits RC2
- 継承
- 属性
例
次のコード例では、文字列の暗号化と暗号化解除を行います。
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);
// Read the decrypted bytes from the decrypting stream
// and place them in a StringBuilder class.
StringBuilder roundtrip = new StringBuilder();
int b = 0;
do
{
b = csDecrypt.ReadByte();
if (b != -1)
{
roundtrip.Append((char)b);
}
} while (b != -1);
// Display the original data and the decrypted data.
Console.WriteLine("Original: {0}", original);
Console.WriteLine("Round Trip: {0}", roundtrip);
}
}
}
Imports System.IO
Imports System.Text
Imports System.Security.Cryptography
Module Crypto
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)
' Read the decrypted bytes from the decrypting stream
' and place them in a StringBuilder class.
Dim roundtrip As New StringBuilder()
Dim b As Integer = 0
Do
b = csDecrypt.ReadByte()
If b <> -1 Then
roundtrip.Append(ChrW(b))
End If
Loop While b <> -1
' Display the original data and the decrypted data.
Console.WriteLine("Original: {0}", original)
Console.WriteLine("Round Trip: {0}", roundtrip)
End Sub
End Module
注釈
RC2CryptoServiceProvider実装では、40 ビットから 128 ビットまでのキー長を 8 ビットずつサポートしています。
RC2CryptoServiceProvider オブジェクトは、8 バイトのブロックでデータを暗号化および復号化するブロック暗号です。 このクラスは、データの最終ブロックが 8 バイト未満の場合に埋め込みます。 このパディングの結果、暗号化されたデータの長さが元のプレーンテキストよりも長くなる可能性があります。
RC2CryptoServiceProvider オブジェクトは salt を使用しないことに注意してください。
Note
新しい対称暗号化アルゴリズムである Advanced Encryption Standard (AES) を使用できます。 Aes クラスではなく、RC2CryptoServiceProvider アルゴリズムとその派生クラスを使用することを検討してください。 RC2CryptoServiceProviderは、レガシ アプリケーションとデータとの互換性のためにのみ使用します。
コンストラクター
| 名前 | 説明 |
|---|---|
| RC2CryptoServiceProvider() |
古い.
RC2CryptoServiceProvider クラスの新しいインスタンスを初期化します。 |
フィールド
| 名前 | 説明 |
|---|---|
| BlockSizeValue |
古い.
暗号化操作のブロック サイズをビット単位で表します。 (継承元 SymmetricAlgorithm) |
| EffectiveKeySizeValue |
古い.
RC2 アルゴリズムで使用される秘密鍵の有効なサイズをビット単位で表します。 (継承元 RC2) |
| FeedbackSizeValue |
古い.
暗号化操作のフィードバック サイズをビット単位で表します。 (継承元 SymmetricAlgorithm) |
| IVValue |
古い.
対称アルゴリズムの初期化ベクトル (IV) を表します。 (継承元 SymmetricAlgorithm) |
| KeySizeValue |
古い.
対称アルゴリズムで使用される秘密鍵のサイズをビット単位で表します。 (継承元 SymmetricAlgorithm) |
| KeyValue |
古い.
対称アルゴリズムの秘密鍵を表します。 (継承元 SymmetricAlgorithm) |
| LegalBlockSizesValue |
古い.
対称アルゴリズムでサポートされるブロック サイズをビット単位で指定します。 (継承元 SymmetricAlgorithm) |
| LegalKeySizesValue |
古い.
対称アルゴリズムでサポートされるキー サイズをビット単位で指定します。 (継承元 SymmetricAlgorithm) |
| ModeValue |
古い.
対称アルゴリズムで使用される暗号モードを表します。 (継承元 SymmetricAlgorithm) |
| PaddingValue |
古い.
対称アルゴリズムで使用されるパディング モードを表します。 (継承元 SymmetricAlgorithm) |
プロパティ
| 名前 | 説明 |
|---|---|
| BlockSize |
古い.
暗号化操作のブロック サイズをビット単位で取得または設定します。 (継承元 SymmetricAlgorithm) |
| EffectiveKeySize |
古い.
RC2 アルゴリズムで使用される秘密鍵の有効なサイズをビット単位で取得または設定します。 |
| FeedbackSize |
古い.
暗号フィードバック (CFB) および出力フィードバック (OFB) 暗号モードの暗号化操作のフィードバック サイズをビット単位で取得または設定します。 (継承元 SymmetricAlgorithm) |
| IV |
古い.
対称アルゴリズムの初期化ベクトル (IV) を取得または設定します。 (継承元 SymmetricAlgorithm) |
| Key |
古い.
対称アルゴリズムの秘密鍵を取得または設定します。 (継承元 SymmetricAlgorithm) |
| KeySize |
古い.
RC2 アルゴリズムで使用される秘密鍵のサイズをビット単位で取得または設定します。 (継承元 RC2) |
| LegalBlockSizes |
古い.
対称アルゴリズムでサポートされているブロック サイズをビット単位で取得します。 (継承元 SymmetricAlgorithm) |
| LegalKeySizes |
古い.
対称アルゴリズムでサポートされているキー サイズをビット単位で取得します。 (継承元 SymmetricAlgorithm) |
| Mode |
古い.
対称アルゴリズムの操作モードを取得または設定します。 (継承元 SymmetricAlgorithm) |
| Padding |
古い.
対称アルゴリズムで使用されるパディング モードを取得または設定します。 (継承元 SymmetricAlgorithm) |
| UseSalt |
古い.
11 バイトの長さ 0 の salt のキーを作成するかどうかを決定する値を取得または設定します。 |
メソッド
明示的なインターフェイスの実装
| 名前 | 説明 |
|---|---|
| IDisposable.Dispose() |
この API は製品インフラストラクチャをサポートします。コードから直接使用するものではありません。
古い.
SymmetricAlgorithmによって使用されるアンマネージ リソースを解放し、必要に応じてマネージド リソースを解放します。 (継承元 SymmetricAlgorithm) |