DESCryptoServiceProvider Třída

Definice

Definuje objekt obálky pro přístup k verzi zprostředkovatele kryptografických služeb (CSP) algoritmu Standard () pro šifrování dat DES .Defines a wrapper object to access the cryptographic service provider (CSP) version of the Data Encryption Standard (DES) algorithm. Tuto třídu nelze zdědit.This class cannot be inherited.

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
Dědičnost
DESCryptoServiceProvider
Atributy

Příklady

Následující příklad kódu používá DESCryptoServiceProvider (implementaci DES ) se zadaným klíčem ( Key ) a inicializační vektor ( IV ) k zašifrování souboru určeného parametrem inName .The following code example uses DESCryptoServiceProvider (an implementation of DES) with the specified key (Key) and initialization vector (IV) to encrypt a file specified by inName. Pak výstup zašifrovaného výsledku do souboru určeného parametrem outName .It then outputs the encrypted result to the file specified by 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

Dešifrování lze zpracovat stejným způsobem. CreateDecryptor místo použijte CreateEncryptor .Decryption can be handled in the same way; use CreateDecryptor instead of CreateEncryptor. Stejný klíč ( Key ) a inicializační vektor (), který se IV používá k zašifrování souboru, se musí použít k dešifrování.The same key (Key) and initialization vector (IV) used to encrypt the file must be used to decrypt it.

Poznámky

Tento algoritmus podporuje délku klíče 64 bitů.This algorithm supports a key length of 64 bits.

Důležité

K dispozici je novější algoritmus symetrického šifrování standard AES (Advanced Encryption Standard) (AES).A newer symmetric encryption algorithm, Advanced Encryption Standard (AES), is available. Zvažte použití Aes třídy namísto DES třídy.Consider using the Aes class instead of the DES class. Používejte DES jenom pro kompatibilitu se staršími aplikacemi a daty.Use DES only for compatibility with legacy applications and data.

Konstruktory

DESCryptoServiceProvider()

Inicializuje novou instanci DESCryptoServiceProvider třídy.Initializes a new instance of the DESCryptoServiceProvider class.

Pole

BlockSizeValue

Představuje velikost bloku v bitech kryptografické operace.Represents the block size, in bits, of the cryptographic operation.

(Zděděno od SymmetricAlgorithm)
FeedbackSizeValue

Představuje velikost zpětné vazby v bitech kryptografické operace.Represents the feedback size, in bits, of the cryptographic operation.

(Zděděno od SymmetricAlgorithm)
IVValue

Představuje inicializační vektor ( IV ) pro symetrický algoritmus.Represents the initialization vector (IV) for the symmetric algorithm.

(Zděděno od SymmetricAlgorithm)
KeySizeValue

Představuje velikost tajného klíče používaného symetrickým algoritmem v bitech.Represents the size, in bits, of the secret key used by the symmetric algorithm.

(Zděděno od SymmetricAlgorithm)
KeyValue

Představuje tajný klíč pro symetrický algoritmus.Represents the secret key for the symmetric algorithm.

(Zděděno od SymmetricAlgorithm)
LegalBlockSizesValue

Určuje velikosti bloků v bitech, které jsou podporovány symetrickým algoritmem.Specifies the block sizes, in bits, that are supported by the symmetric algorithm.

(Zděděno od SymmetricAlgorithm)
LegalKeySizesValue

Určuje velikosti klíčů v bitech, které jsou podporovány symetrickým algoritmem.Specifies the key sizes, in bits, that are supported by the symmetric algorithm.

(Zděděno od SymmetricAlgorithm)
ModeValue

Představuje režim šifrování použitý v symetrickém algoritmu.Represents the cipher mode used in the symmetric algorithm.

(Zděděno od SymmetricAlgorithm)
PaddingValue

Představuje režim odsazení použitý v symetrickém algoritmu.Represents the padding mode used in the symmetric algorithm.

(Zděděno od SymmetricAlgorithm)

Vlastnosti

BlockSize

Získá nebo nastaví velikost bloku kryptografické operace v bitech.Gets or sets the block size, in bits, of the cryptographic operation.

(Zděděno od SymmetricAlgorithm)
FeedbackSize

Získá nebo nastaví velikost zpětné vazby v bitech pro šifrovací operace CFB (Cipher Feedback) a zpětná vazba (OFB) pro šifrovací režimy.Gets or sets the feedback size, in bits, of the cryptographic operation for the Cipher Feedback (CFB) and Output Feedback (OFB) cipher modes.

(Zděděno od SymmetricAlgorithm)
IV

Získá nebo nastaví inicializační vektor ( IV ) pro symetrický algoritmus.Gets or sets the initialization vector (IV) for the symmetric algorithm.

(Zděděno od SymmetricAlgorithm)
Key

Získá nebo nastaví tajný klíč pro algoritmus šifrování dat Standard ( DES ).Gets or sets the secret key for the Data Encryption Standard (DES) algorithm.

(Zděděno od DES)
KeySize

Získá nebo nastaví velikost tajného klíče používaného symetrickým algoritmem v bitech.Gets or sets the size, in bits, of the secret key used by the symmetric algorithm.

(Zděděno od SymmetricAlgorithm)
LegalBlockSizes

Získá velikosti bloků v bitech, které jsou podporovány symetrickým algoritmem.Gets the block sizes, in bits, that are supported by the symmetric algorithm.

(Zděděno od SymmetricAlgorithm)
LegalKeySizes

Získá velikosti klíčů, které jsou podporovány symetrickým algoritmem v bitech.Gets the key sizes, in bits, that are supported by the symmetric algorithm.

(Zděděno od SymmetricAlgorithm)
Mode

Získá nebo nastaví režim pro provoz symetrického algoritmu.Gets or sets the mode for operation of the symmetric algorithm.

(Zděděno od SymmetricAlgorithm)
Padding

Získá nebo nastaví režim odsazení použitý v symetrickém algoritmu.Gets or sets the padding mode used in the symmetric algorithm.

(Zděděno od SymmetricAlgorithm)

Metody

Clear()

Uvolní všechny prostředky používané SymmetricAlgorithm třídou.Releases all resources used by the SymmetricAlgorithm class.

(Zděděno od SymmetricAlgorithm)
CreateDecryptor()

Vytvoří symetrický objekt dešifrování s aktuální Key vlastností a inicializačním vektorem ( IV ).Creates a symmetric decryptor object with the current Key property and initialization vector (IV).

CreateDecryptor()

Vytvoří symetrický objekt dešifrování s aktuální Key vlastností a inicializačním vektorem ( IV ).Creates a symmetric decryptor object with the current Key property and initialization vector (IV).

(Zděděno od SymmetricAlgorithm)
CreateDecryptor(Byte[], Byte[])

Vytvoří dešifrovací objekt Standard () dešifrování symetrického šifrování dat DES pomocí zadaného klíče ( Key ) a inicializačního vektoru ( IV ).Creates a symmetric Data Encryption Standard (DES) decryptor object with the specified key (Key) and initialization vector (IV).

CreateEncryptor()

Vytvoří symetrický objekt šifry s aktuální Key vlastností a inicializačním vektorem ( IV ).Creates a symmetric encryptor object with the current Key property and initialization vector (IV).

CreateEncryptor()

Vytvoří symetrický objekt šifry s aktuální Key vlastností a inicializačním vektorem ( IV ).Creates a symmetric encryptor object with the current Key property and initialization vector (IV).

(Zděděno od SymmetricAlgorithm)
CreateEncryptor(Byte[], Byte[])

Vytvoří objekt šifry Standard () pro symetrický datový šifrování ( DES ) se zadaným klíčem ( Key ) a inicializačním vektorem ( IV ).Creates a symmetric Data Encryption Standard (DES) encryptor object with the specified key (Key) and initialization vector (IV).

Dispose()

Uvolní všechny prostředky používané aktuální instancí SymmetricAlgorithm třídy.Releases all resources used by the current instance of the SymmetricAlgorithm class.

(Zděděno od SymmetricAlgorithm)
Dispose(Boolean)

Uvolní nespravované prostředky používané SymmetricAlgorithm a volitelně uvolňuje spravované prostředky.Releases the unmanaged resources used by the SymmetricAlgorithm and optionally releases the managed resources.

(Zděděno od SymmetricAlgorithm)
Equals(Object)

Určí, zda se zadaný objekt rovná aktuálnímu objektu.Determines whether the specified object is equal to the current object.

(Zděděno od Object)
GenerateIV()

Vygeneruje náhodný vektor inicializace ( IV ), který se má použít pro algoritmus.Generates a random initialization vector (IV) to use for the algorithm.

GenerateKey()

Vygeneruje náhodný klíč ( Key ), který se má použít pro algoritmus.Generates a random key (Key) to be used for the algorithm.

GetHashCode()

Slouží jako výchozí funkce hash.Serves as the default hash function.

(Zděděno od Object)
GetType()

Získá Type aktuální instanci.Gets the Type of the current instance.

(Zděděno od Object)
MemberwiseClone()

Vytvoří kopii aktuálního seznamu Object .Creates a shallow copy of the current Object.

(Zděděno od Object)
ToString()

Vrátí řetězec, který představuje aktuální objekt.Returns a string that represents the current object.

(Zděděno od Object)
ValidKeySize(Int32)

Určuje, zda je zadaná velikost klíče platná pro aktuální algoritmus.Determines whether the specified key size is valid for the current algorithm.

(Zděděno od SymmetricAlgorithm)

Explicitní implementace rozhraní

IDisposable.Dispose()

Toto rozhraní API podporuje produktovou infrastrukturu a není určené k použití přímo z uživatelského kódu.

Uvolní nespravované prostředky používané SymmetricAlgorithm a volitelně uvolňuje spravované prostředky.Releases the unmanaged resources used by the SymmetricAlgorithm and optionally releases the managed resources.

(Zděděno od SymmetricAlgorithm)

Platí pro