DESCryptoServiceProvider クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
注意事項
Derived cryptographic types are obsolete. Use the Create method on the base type instead.
DES (Data Encryption Standard) アルゴリズムの暗号サービス プロバイダー (CSP: Cryptographic Service Provider) バージョンにアクセスするためのラッパー オブジェクトを定義します。 このクラスは継承できません。
public ref class DESCryptoServiceProvider sealed : System::Security::Cryptography::DES
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}")]
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.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
[<System.Runtime.InteropServices.ComVisible(true)>]
type DESCryptoServiceProvider = class
inherit DES
Public NotInheritable Class DESCryptoServiceProvider
Inherits DES
- 継承
- 属性
例
次のDESコード例では、指定したキー () と初期化ベクトル (IV) を使用して (Keyの実装) をinName
使用DESCryptoServiceProviderして、指定されたファイルを暗号化します。 次に、暗号化された結果を指定 outName
されたファイルに出力します。
void EncryptData( String^ inName, String^ outName, array<Byte>^desKey, array<Byte>^desIV )
{
//Create the file streams to handle the input and output files.
FileStream^ fin = gcnew FileStream( inName,FileMode::Open,FileAccess::Read );
FileStream^ fout = gcnew FileStream( outName,FileMode::OpenOrCreate,FileAccess::Write );
fout->SetLength( 0 );
//Create variables to help with read and write.
array<Byte>^bin = gcnew array<Byte>(100);
long rdlen = 0; //This is the total number of bytes written.
long totlen = (long)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 = gcnew DESCryptoServiceProvider;
CryptoStream^ encStream = gcnew 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 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 ビットに対応しています。
重要
新しい対称暗号化アルゴリズムである 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 |
DES (Data Encryption Standard) アルゴリズム用の秘密鍵 (共通鍵) を取得または設定します。 (継承元 DES) |
KeySize |
対称アルゴリズムで使用する共有キーのサイズをビット単位で取得または設定します。 (継承元 SymmetricAlgorithm) |
LegalBlockSizes |
対称アルゴリズムでサポートされているブロック サイズをビット単位で取得します。 (継承元 SymmetricAlgorithm) |
LegalKeySizes |
対称アルゴリズムでサポートされているキー サイズをビット単位で取得します。 (継承元 SymmetricAlgorithm) |
Mode |
対称アルゴリズムの操作モードを取得または設定します。 (継承元 SymmetricAlgorithm) |
Padding |
対称アルゴリズムで使用する埋め込みモードを取得または設定します。 (継承元 SymmetricAlgorithm) |
メソッド
明示的なインターフェイスの実装
IDisposable.Dispose() |
この API は製品インフラストラクチャをサポートします。コードから直接使用するものではありません。 SymmetricAlgorithm によって使用されているアンマネージド リソースを解放し、オプションでマネージド リソースも解放します。 (継承元 SymmetricAlgorithm) |