DESCryptoServiceProvider クラス

定義

Data Encryption Standard (DES) アルゴリズムの暗号化サービス プロバイダー (CSP) バージョンにアクセスするためのラッパー オブジェクトを定義します。 このクラスは継承できません。

public ref class DESCryptoServiceProvider sealed : System::Security::Cryptography::DES
public sealed class DESCryptoServiceProvider : System.Security.Cryptography.DES
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class DESCryptoServiceProvider : System.Security.Cryptography.DES
type DESCryptoServiceProvider = class
    inherit DES
[<System.Runtime.InteropServices.ComVisible(true)>]
type DESCryptoServiceProvider = class
    inherit DES
Public NotInheritable Class DESCryptoServiceProvider
Inherits DES
継承
DESCryptoServiceProvider
属性

次のコード例では、指定したキー (DESCryptoServiceProvider) と初期化ベクトル (DES) を使用してKey (IVの実装) を使用して、inNameで指定されたファイルを暗号化します。 その後、暗号化された結果が、 outNameで指定されたファイルに出力されます。

private static void EncryptData(string inName, string outName, byte[] desKey, byte[] desIV)
 {
     //Create the file streams to handle the input and output files.
     FileStream fin = new FileStream(inName, FileMode.Open, FileAccess.Read);
     FileStream fout = new FileStream(outName, FileMode.OpenOrCreate, FileAccess.Write);
     fout.SetLength(0);

     //Create variables to help with read and write.
     byte[] bin = new byte[100]; //This is intermediate storage for the encryption.
     long rdlen = 0;              //This is the total number of bytes written.
     long totlen = fin.Length;    //This is the total length of the input file.
     int len;                     //This is the number of bytes to be written at a time.

     DES des = new DESCryptoServiceProvider();
     CryptoStream encStream = new CryptoStream(fout, des.CreateEncryptor(desKey, desIV), CryptoStreamMode.Write);

     Console.WriteLine("Encrypting...");

     //Read from the input file, then encrypt and write to the output file.
     while(rdlen < totlen)
     {
         len = fin.Read(bin, 0, 100);
         encStream.Write(bin, 0, len);
         rdlen = rdlen + len;
         Console.WriteLine("{0} bytes processed", rdlen);
     }

     encStream.Close();
     fout.Close();
     fin.Close();
 }
Private Shared Sub EncryptData(inName As String, outName As String, _
desKey() As Byte, desIV() As Byte)

    'Create the file streams to handle the input and output files.
    Dim fin As New FileStream(inName, FileMode.Open, FileAccess.Read)
    Dim fout As New FileStream(outName, FileMode.OpenOrCreate, _
       FileAccess.Write)
    fout.SetLength(0)
    
    'Create variables to help with read and write.
    Dim bin(4096) As Byte 'This is intermediate storage for the encryption.
    Dim rdlen As Long = 0 'This is the total number of bytes written.
    Dim totlen As Long = fin.Length 'Total length of the input file.
    Dim len As Integer 'This is the number of bytes to be written at a time.
    Dim des As New DESCryptoServiceProvider()
    Dim encStream As New CryptoStream(fout, _
       des.CreateEncryptor(desKey, desIV), CryptoStreamMode.Write)
    
    Console.WriteLine("Encrypting...")
    
    'Read from the input file, then encrypt and write to the output file.
    While rdlen < totlen
        len = fin.Read(bin, 0, 4096)
        encStream.Write(bin, 0, len)
        rdlen = Convert.ToInt32(rdlen + len / des.BlockSize * des.BlockSize)
        Console.WriteLine("Processed {0} bytes, {1} bytes total", len, _
           rdlen)
    End While
    
    encStream.Close()
End Sub

復号化は同じ方法で処理できます。CreateEncryptorの代わりにCreateDecryptorを使用します。 ファイルの暗号化に使用するのと同じキー (Key) と初期化ベクトル (IV) を使用して暗号化を解除する必要があります。

注釈

このアルゴリズムは、64 ビットのキー長をサポートします。

Important

新しい対称暗号化アルゴリズムである Advanced Encryption Standard (AES) を使用できます。 Aes クラスではなく、DES クラスを使用することを検討してください。 DESは、レガシ アプリケーションとデータとの互換性のためにのみ使用します。

コンストラクター

名前 説明
DESCryptoServiceProvider()

DESCryptoServiceProvider クラスの新しいインスタンスを初期化します。

フィールド

名前 説明
BlockSizeValue

暗号化操作のブロック サイズをビット単位で表します。

(継承元 SymmetricAlgorithm)
FeedbackSizeValue

暗号化操作のフィードバック サイズをビット単位で表します。

(継承元 SymmetricAlgorithm)
IVValue

対称アルゴリズムの初期化ベクトル (IV) を表します。

(継承元 SymmetricAlgorithm)
KeySizeValue

対称アルゴリズムで使用される秘密鍵のサイズをビット単位で表します。

(継承元 SymmetricAlgorithm)
KeyValue

対称アルゴリズムの秘密鍵を表します。

(継承元 SymmetricAlgorithm)
LegalBlockSizesValue

対称アルゴリズムでサポートされるブロック サイズをビット単位で指定します。

(継承元 SymmetricAlgorithm)
LegalKeySizesValue

対称アルゴリズムでサポートされるキー サイズをビット単位で指定します。

(継承元 SymmetricAlgorithm)
ModeValue

対称アルゴリズムで使用される暗号モードを表します。

(継承元 SymmetricAlgorithm)
PaddingValue

対称アルゴリズムで使用されるパディング モードを表します。

(継承元 SymmetricAlgorithm)

プロパティ

名前 説明
BlockSize

暗号化操作のブロック サイズをビット単位で取得または設定します。

(継承元 SymmetricAlgorithm)
FeedbackSize

暗号フィードバック (CFB) および出力フィードバック (OFB) 暗号モードの暗号化操作のフィードバック サイズをビット単位で取得または設定します。

(継承元 SymmetricAlgorithm)
IV

対称アルゴリズムの初期化ベクトル (IV) を取得または設定します。

(継承元 SymmetricAlgorithm)
Key

Data Encryption Standard (DES) アルゴリズムの秘密鍵を取得または設定します。

(継承元 DES)
KeySize

対称アルゴリズムで使用される秘密鍵のサイズをビット単位で取得または設定します。

(継承元 SymmetricAlgorithm)
LegalBlockSizes

対称アルゴリズムでサポートされているブロック サイズをビット単位で取得します。

(継承元 SymmetricAlgorithm)
LegalKeySizes

対称アルゴリズムでサポートされているキー サイズをビット単位で取得します。

(継承元 SymmetricAlgorithm)
Mode

対称アルゴリズムの操作モードを取得または設定します。

(継承元 SymmetricAlgorithm)
Padding

対称アルゴリズムで使用されるパディング モードを取得または設定します。

(継承元 SymmetricAlgorithm)

メソッド

名前 説明
Clear()

SymmetricAlgorithm クラスによって使用されるすべてのリソースを解放します。

(継承元 SymmetricAlgorithm)
CreateDecryptor()

現在の Key プロパティと初期化ベクトル (IV) を使用して対称復号化オブジェクトを作成します。

CreateDecryptor()

現在の Key プロパティと初期化ベクトル (IV) を使用して対称復号化オブジェクトを作成します。

(継承元 SymmetricAlgorithm)
CreateDecryptor(Byte[], Byte[])

指定したキー (Key) と初期化ベクトル (IV) を使用して、対称 Data Encryption Standard (DES) 復号化オブジェクトを作成します。

CreateEncryptor()

現在の Key プロパティと初期化ベクトル (IV) を使用して対称暗号化オブジェクトを作成します。

CreateEncryptor()

現在の Key プロパティと初期化ベクトル (IV) を使用して対称暗号化オブジェクトを作成します。

(継承元 SymmetricAlgorithm)
CreateEncryptor(Byte[], Byte[])

指定したキー (DES) と初期化ベクトル (Key) を使用して、対称 Data Encryption Standard (IV) 暗号化オブジェクトを作成します。

Dispose()

SymmetricAlgorithm クラスの現在のインスタンスで使用されているすべてのリソースを解放します。

(継承元 SymmetricAlgorithm)
Dispose(Boolean)

SymmetricAlgorithmによって使用されるアンマネージ リソースを解放し、必要に応じてマネージド リソースを解放します。

(継承元 SymmetricAlgorithm)
Equals(Object)

指定したオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GenerateIV()

アルゴリズムに使用するランダム初期化ベクトル (IV) を生成します。

GenerateKey()

アルゴリズムに使用するランダム キー (Key) を生成します。

GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Objectの簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)
ValidKeySize(Int32)

指定したキー サイズが現在のアルゴリズムに対して有効かどうかを判断します。

(継承元 SymmetricAlgorithm)

明示的なインターフェイスの実装

名前 説明
IDisposable.Dispose()

この API は製品インフラストラクチャをサポートします。コードから直接使用するものではありません。

SymmetricAlgorithmによって使用されるアンマネージ リソースを解放し、必要に応じてマネージド リソースを解放します。

(継承元 SymmetricAlgorithm)

適用対象

こちらもご覧ください