DESCryptoServiceProvider クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
注意事項
Derived cryptographic types are obsolete. Use the Create method on the base type instead.
Data Encryption Standard (DES) アルゴリズムの暗号化サービス プロバイダー (CSP) バージョンにアクセスするためのラッパー オブジェクトを定義します。 このクラスは継承できません。
public ref class DESCryptoServiceProvider sealed : System::Security::Cryptography::DES
[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 DESCryptoServiceProvider : 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
[<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 DESCryptoServiceProvider = class
inherit DES
type DESCryptoServiceProvider = class
inherit DES
[<System.Runtime.InteropServices.ComVisible(true)>]
type DESCryptoServiceProvider = class
inherit DES
Public NotInheritable Class DESCryptoServiceProvider
Inherits DES
- 継承
- 属性
例
次のコード例では、指定したキー (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
復号化は同じ方法で処理できます。CreateDecryptorの代わりにCreateEncryptorを使用します。 ファイルの暗号化に使用するのと同じキー (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) |
メソッド
明示的なインターフェイスの実装
| 名前 | 説明 |
|---|---|
| IDisposable.Dispose() |
この API は製品インフラストラクチャをサポートします。コードから直接使用するものではありません。
古い.
SymmetricAlgorithmによって使用されるアンマネージ リソースを解放し、必要に応じてマネージド リソースを解放します。 (継承元 SymmetricAlgorithm) |