TripleDES TripleDES TripleDES TripleDES Class

Definición

Representa la clase base de los algoritmos 3DES (Triple Data Encryption Standard) de la cual deben derivarse todas las implementaciones de TripleDES. Represents the base class for Triple Data Encryption Standard algorithms from which all TripleDES implementations must derive.

public ref class TripleDES abstract : System::Security::Cryptography::SymmetricAlgorithm
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class TripleDES : System.Security.Cryptography.SymmetricAlgorithm
type TripleDES = class
    inherit SymmetricAlgorithm
Public MustInherit Class TripleDES
Inherits SymmetricAlgorithm
Herencia
Derivado
Atributos

Ejemplos

El siguiente código de ejemplo se utiliza método TripleDESCryptoServiceProvider con la clave especificada (Key) y el vector de inicialización (IV) para cifrar un archivo especificado por inName.The following code example method uses TripleDESCryptoServiceProvider with the specified key (Key) and initialization vector (IV) to encrypt a file specified by inName. A continuación, genera el resultado cifrado en el archivo especificado por outName.It then outputs the encrypted result to the file specified by outName.

void EncryptData( String^ inName, String^ outName, array<Byte>^tdesKey, array<Byte>^tdesIV )
{
   
   //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.

   TripleDESCryptoServiceProvider^ tdes = gcnew TripleDESCryptoServiceProvider;
   CryptoStream^ encStream = gcnew CryptoStream( fout,tdes->CreateEncryptor( tdesKey, tdesIV ),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();
}

private static void EncryptData(String inName, String outName, byte[] tdesKey, byte[] tdesIV)
{    
    //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.

    TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();          
    CryptoStream encStream = new CryptoStream(fout, tdes.CreateEncryptor(tdesKey, tdesIV), 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();                     
}
Private Shared Sub EncryptData(inName As String, outName As String, _
   tdesKey() As Byte, tdesIV() 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(100) 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 'This is the total length of the input file.
    Dim len As Integer 'This is the number of bytes to be written at a time.
    Dim tdes As New TripleDESCryptoServiceProvider()
    Dim encStream As New CryptoStream(fout, _
       tdes.CreateEncryptor(tdesKey, tdesIV), 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)
    End While
        
    encStream.Close()
End Sub

Descifrado puede controlarse en la misma manera; usar CreateDecryptor en lugar de CreateEncryptor.Decryption can be handled in the same way; use CreateDecryptor instead of CreateEncryptor. La misma clave (Key) y el vector de inicialización (IV) usado para cifrar el archivo se debe usar para descifrarlos.The same key (Key) and initialization vector (IV) used to encrypt the file must be used to decrypt it.

Comentarios

TripleDES utiliza tres iteraciones sucesivas de la DES algoritmo.TripleDES uses three successive iterations of the DES algorithm. Puede usar dos o tres claves de 56 bits.It can use either two or three 56-bit keys.

Nota

Un algoritmo de cifrado simétrico más reciente, Advanced Encryption Standard (AES), está disponible.A newer symmetric encryption algorithm, Advanced Encryption Standard (AES), is available. Considere el uso de la Aes clase y sus clases derivadas en lugar de la TripleDES clase.Consider using the Aes class and its derived classes instead of the TripleDES class. Use TripleDES únicamente por compatibilidad con aplicaciones heredadas y los datos.Use TripleDES only for compatibility with legacy applications and data.

Este algoritmo admite longitudes de clave de 128 bits para 192 bits en incrementos de 64 bits.This algorithm supports key lengths from 128 bits to 192 bits in increments of 64 bits.

Constructores

TripleDES() TripleDES() TripleDES() TripleDES()

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

Propiedades

BlockSize BlockSize BlockSize 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.

(Inherited from SymmetricAlgorithm)
FeedbackSize FeedbackSize FeedbackSize FeedbackSize

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

(Inherited from SymmetricAlgorithm)
IV IV IV 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.

(Inherited from SymmetricAlgorithm)
Key Key Key Key

Obtiene o establece la clave secreta del algoritmo TripleDES. Gets or sets the secret key for the TripleDES algorithm.

KeySize KeySize KeySize KeySize

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

(Inherited from SymmetricAlgorithm)
LegalBlockSizes LegalBlockSizes LegalBlockSizes LegalBlockSizes
LegalKeySizes LegalKeySizes LegalKeySizes LegalKeySizes
Mode Mode Mode Mode

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

(Inherited from SymmetricAlgorithm)
Padding Padding Padding 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.

(Inherited from SymmetricAlgorithm)

Métodos

Clear() Clear() Clear() Clear()

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

(Inherited from SymmetricAlgorithm)
Create() Create() Create() Create()

Crea una instancia de un objeto criptográfico para realizar el algoritmo TripleDES. Creates an instance of a cryptographic object to perform the TripleDES algorithm.

Create(String) Create(String) Create(String) Create(String)

Crea una instancia de un objeto criptográfico para ejecutar la implementación especificada del algoritmo TripleDES. Creates an instance of a cryptographic object to perform the specified implementation of the TripleDES algorithm.

CreateDecryptor() CreateDecryptor() CreateDecryptor() 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).

(Inherited from SymmetricAlgorithm)
CreateDecryptor(Byte[], Byte[]) CreateDecryptor(Byte[], Byte[]) CreateDecryptor(Byte[], Byte[]) CreateDecryptor(Byte[], Byte[])

Cuando se invalida en una clase derivada, crea un objeto descifrador simétrico con la propiedad Key y el vector de inicialización (IV) especificados. When overridden in a derived class, creates a symmetric decryptor object with the specified Key property and initialization vector (IV).

(Inherited from SymmetricAlgorithm)
CreateEncryptor() CreateEncryptor() CreateEncryptor() 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).

(Inherited from SymmetricAlgorithm)
CreateEncryptor(Byte[], Byte[]) CreateEncryptor(Byte[], Byte[]) CreateEncryptor(Byte[], Byte[]) CreateEncryptor(Byte[], Byte[])

Cuando se invalida en una clase derivada, se crea un objeto cifrador simétrico con la propiedad Key y el vector de inicialización (IV) especificados. When overridden in a derived class, creates a symmetric encryptor object with the specified Key property and initialization vector (IV).

(Inherited from SymmetricAlgorithm)
Dispose() Dispose() Dispose() 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.

(Inherited from SymmetricAlgorithm)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) 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.

(Inherited from SymmetricAlgorithm)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

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

(Inherited from Object)
GenerateIV() GenerateIV() GenerateIV() GenerateIV()

Cuando se invalida en una clase derivada, genera un vector de inicialización aleatorio (IV), que se usa para el algoritmo. When overridden in a derived class, generates a random initialization vector (IV) to use for the algorithm.

(Inherited from SymmetricAlgorithm)
GenerateKey() GenerateKey() GenerateKey() GenerateKey()

Cuando se invalida en una clase derivada, genera una clave aleatoria (Key), que se usa para el algoritmo. When overridden in a derived class, generates a random key (Key) to use for the algorithm.

(Inherited from SymmetricAlgorithm)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

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

(Inherited from Object)
GetType() GetType() GetType() GetType()

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

(Inherited from Object)
IsWeakKey(Byte[]) IsWeakKey(Byte[]) IsWeakKey(Byte[]) IsWeakKey(Byte[])

Determina si la clave especificada es débil. Determines whether the specified key is weak.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

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

(Inherited from Object)
ToString() ToString() ToString() ToString()

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

(Inherited from Object)
ValidKeySize(Int32) ValidKeySize(Int32) ValidKeySize(Int32) 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.

(Inherited from SymmetricAlgorithm)

Campos

BlockSizeValue BlockSizeValue BlockSizeValue 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.

(Inherited from SymmetricAlgorithm)
FeedbackSizeValue FeedbackSizeValue FeedbackSizeValue 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.

(Inherited from SymmetricAlgorithm)
IVValue IVValue IVValue IVValue

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

(Inherited from SymmetricAlgorithm)
KeySizeValue KeySizeValue KeySizeValue 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.

(Inherited from SymmetricAlgorithm)
KeyValue KeyValue KeyValue KeyValue

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

(Inherited from SymmetricAlgorithm)
LegalBlockSizesValue LegalBlockSizesValue LegalBlockSizesValue 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.

(Inherited from SymmetricAlgorithm)
LegalKeySizesValue LegalKeySizesValue LegalKeySizesValue 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.

(Inherited from SymmetricAlgorithm)
ModeValue ModeValue ModeValue ModeValue

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

(Inherited from SymmetricAlgorithm)
PaddingValue PaddingValue PaddingValue PaddingValue

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

(Inherited from SymmetricAlgorithm)

Implementaciones de interfaz explícitas

IDisposable.Dispose() IDisposable.Dispose() IDisposable.Dispose() IDisposable.Dispose()

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.

(Inherited from SymmetricAlgorithm)

Se aplica a

Consultar también