DESCryptoServiceProvider Clase

Definición

Define un objeto contenedor para obtener acceso a la versión del proveedor de servicios criptográficos (CSP) del algoritmo Estándar de cifrado de datos (DES).Defines a wrapper object to access the cryptographic service provider (CSP) version of the Data Encryption Standard (DES) algorithm. Esta clase no puede heredarse.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
Herencia
DESCryptoServiceProvider
Atributos

Ejemplos

En el ejemplo de código siguiente DESCryptoServiceProvider se usa (una implementación de DES ) con la clave ( Key ) y el vector de inicialización () especificados IV para cifrar un archivo especificado por 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. A continuación, envía el resultado cifrado al archivo especificado por 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

El descifrado se puede administrar de la misma manera; Use CreateDecryptor en lugar de CreateEncryptor .Decryption can be handled in the same way; use CreateDecryptor instead of CreateEncryptor. Se debe usar la misma clave ( Key ) y el vector de inicialización ( IV ) que se usa para cifrar el archivo para descifrarlo.The same key (Key) and initialization vector (IV) used to encrypt the file must be used to decrypt it.

Comentarios

Este algoritmo admite una longitud de clave de 64 bits.This algorithm supports a key length of 64 bits.

Importante

Hay disponible un nuevo algoritmo de cifrado simétrico, Estándar de cifrado avanzado (AES).A newer symmetric encryption algorithm, Advanced Encryption Standard (AES), is available. Considere la posibilidad Aes de usar la clase en lugar de la DES clase.Consider using the Aes class instead of the DES class. Use DES solo para la compatibilidad con las aplicaciones y los datos heredados.Use DES only for compatibility with legacy applications and data.

Constructores

DESCryptoServiceProvider()

Inicializa una nueva instancia de la clase DESCryptoServiceProvider.Initializes a new instance of the DESCryptoServiceProvider class.

Campos

BlockSizeValue

Representa el tamaño del bloque de la operación criptográfica en bits.Represents the block size, in bits, of the cryptographic operation.

(Heredado de SymmetricAlgorithm)
FeedbackSizeValue

Representa el tamaño de respuesta de la operación criptográfica en bits.Represents the feedback size, in bits, of the cryptographic operation.

(Heredado de SymmetricAlgorithm)
IVValue

Representa el vector de inicialización (IV) del algoritmo simétrico.Represents the initialization vector (IV) for the symmetric algorithm.

(Heredado de SymmetricAlgorithm)
KeySizeValue

Representa el tamaño en bits de la clave secreta que usa el algoritmo simétrico.Represents the size, in bits, of the secret key used by the symmetric algorithm.

(Heredado de SymmetricAlgorithm)
KeyValue

Representa la clave secreta del algoritmo simétrico.Represents the secret key for the symmetric algorithm.

(Heredado de SymmetricAlgorithm)
LegalBlockSizesValue

Especifica los tamaños de bloque, en bits, admitidos por el algoritmo simétrico.Specifies the block sizes, in bits, that are supported by the symmetric algorithm.

(Heredado de SymmetricAlgorithm)
LegalKeySizesValue

Especifica los tamaños de clave, en bits, admitidos por el algoritmo simétrico.Specifies the key sizes, in bits, that are supported by the symmetric algorithm.

(Heredado de SymmetricAlgorithm)
ModeValue

Representa el modo de cifrado usado en el algoritmo simétrico.Represents the cipher mode used in the symmetric algorithm.

(Heredado de SymmetricAlgorithm)
PaddingValue

Representa el modo de relleno usado en el algoritmo simétrico.Represents the padding mode used in the symmetric algorithm.

(Heredado de SymmetricAlgorithm)

Propiedades

BlockSize

Obtiene o establece el tamaño del bloque de la operación criptográfica en bits.Gets or sets the block size, in bits, of the cryptographic operation.

(Heredado de SymmetricAlgorithm)
FeedbackSize

Obtiene o establece el tamaño de los comentarios, en bits, de la operación criptográfica de los modos de cifrado Comentarios de cifrado (CFB) y Comentarios de salida (OFB).Gets or sets the feedback size, in bits, of the cryptographic operation for the Cipher Feedback (CFB) and Output Feedback (OFB) cipher modes.

(Heredado de SymmetricAlgorithm)
IV

Obtiene o establece el vector de inicialización (IV) del algoritmo simétrico.Gets or sets the initialization vector (IV) for the symmetric algorithm.

(Heredado de SymmetricAlgorithm)
Key

Obtiene o establece la clave secreta para el algoritmo del Estándar de cifrado de datos (DES).Gets or sets the secret key for the Data Encryption Standard (DES) algorithm.

(Heredado de DES)
KeySize

Obtiene o establece el tamaño de la clave secreta utilizada por el algoritmo simétrico en bits.Gets or sets the size, in bits, of the secret key used by the symmetric algorithm.

(Heredado de SymmetricAlgorithm)
LegalBlockSizes

Obtiene los tamaños de bloque, en bits, admitidos por el algoritmo simétrico.Gets the block sizes, in bits, that are supported by the symmetric algorithm.

(Heredado de SymmetricAlgorithm)
LegalKeySizes

Obtiene los tamaños de clave, en bits, admitidos por el algoritmo simétrico.Gets the key sizes, in bits, that are supported by the symmetric algorithm.

(Heredado de SymmetricAlgorithm)
Mode

Obtiene o establece el modo de funcionamiento del algoritmo simétrico.Gets or sets the mode for operation of the symmetric algorithm.

(Heredado de SymmetricAlgorithm)
Padding

Obtiene o establece el modo de relleno usado en el algoritmo simétrico.Gets or sets the padding mode used in the symmetric algorithm.

(Heredado de SymmetricAlgorithm)

Métodos

Clear()

Libera todos los recursos que utiliza la clase SymmetricAlgorithm.Releases all resources used by the SymmetricAlgorithm class.

(Heredado de SymmetricAlgorithm)
CreateDecryptor()

Crea un objeto descifrador simétrico con la propiedad Key y el vector de inicialización (IV) actuales.Creates a symmetric decryptor object with the current Key property and initialization vector (IV).

CreateDecryptor()

Crea un objeto descifrador simétrico con la propiedad Key y el vector de inicialización (IV) actuales.Creates a symmetric decryptor object with the current Key property and initialization vector (IV).

(Heredado de SymmetricAlgorithm)
CreateDecryptor(Byte[], Byte[])

Crea un objeto descifrador DES (Estándar de cifrado de datos) simétrico con la propiedad Key y el vector de inicialización especificados (IV).Creates a symmetric Data Encryption Standard (DES) decryptor object with the specified key (Key) and initialization vector (IV).

CreateEncryptor()

Crea un objeto cifrador simétrico con la propiedad Key y el vector de inicialización (IV) actuales.Creates a symmetric encryptor object with the current Key property and initialization vector (IV).

CreateEncryptor()

Crea un objeto cifrador simétrico con la propiedad Key y el vector de inicialización (IV) actuales.Creates a symmetric encryptor object with the current Key property and initialization vector (IV).

(Heredado de SymmetricAlgorithm)
CreateEncryptor(Byte[], Byte[])

Crea un objeto descifrador DES (Estándar de cifrado de datos) simétrico con la propiedad Key y el vector de inicialización especificados (IV).Creates a symmetric Data Encryption Standard (DES) encryptor object with the specified key (Key) and initialization vector (IV).

Dispose()

Libera todos los recursos usados por la instancia actual de la clase SymmetricAlgorithm.Releases all resources used by the current instance of the SymmetricAlgorithm class.

(Heredado de SymmetricAlgorithm)
Dispose(Boolean)

Libera los recursos no administrados que usa SymmetricAlgorithm y, de forma opcional, libera los recursos administrados.Releases the unmanaged resources used by the SymmetricAlgorithm and optionally releases the managed resources.

(Heredado de SymmetricAlgorithm)
Equals(Object)

Determina si el objeto especificado es igual que el objeto actual.Determines whether the specified object is equal to the current object.

(Heredado de Object)
GenerateIV()

Genera un vector de inicialización aleatorio (IV) que se va a utilizar para el algoritmo.Generates a random initialization vector (IV) to use for the algorithm.

GenerateKey()

Genera una propiedad (Key) aleatoria que se va a utilizar para el algoritmo.Generates a random key (Key) to be used for the algorithm.

GetHashCode()

Sirve como la función hash predeterminada.Serves as the default hash function.

(Heredado de Object)
GetType()

Obtiene el Type de la instancia actual.Gets the Type of the current instance.

(Heredado de Object)
MemberwiseClone()

Crea una copia superficial del Object actual.Creates a shallow copy of the current Object.

(Heredado de Object)
ToString()

Devuelve una cadena que representa el objeto actual.Returns a string that represents the current object.

(Heredado de Object)
ValidKeySize(Int32)

Determina si el tamaño de clave especificado es válido para el algoritmo actual.Determines whether the specified key size is valid for the current algorithm.

(Heredado de SymmetricAlgorithm)

Implementaciones de interfaz explícitas

IDisposable.Dispose()

Esta API admite la infraestructura de producto y no está pensada para usarse directamente en el código.

Libera los recursos no administrados que usa SymmetricAlgorithm y, de forma opcional, libera los recursos administrados.Releases the unmanaged resources used by the SymmetricAlgorithm and optionally releases the managed resources.

(Heredado de SymmetricAlgorithm)

Se aplica a