DESCryptoServiceProvider Sınıf

Tanım

Veri şifreleme standardı () algoritmasının şifreleme hizmeti sağlayıcısı (CSP) sürümüne erişmek için bir sarmalayıcı nesnesi tanımlar DES .Defines a wrapper object to access the cryptographic service provider (CSP) version of the Data Encryption Standard (DES) algorithm. Bu sınıf devralınamaz.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
Devralma
DESCryptoServiceProvider
Öznitelikler

Örnekler

Aşağıdaki kod örneği, DESCryptoServiceProvider DES Key IV tarafından belirtilen bir dosyayı şifrelemek için belirtilen anahtar () ve başlatma vektörü () ile birlikte (bir uygulamasını) kullanır 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. Daha sonra şifreli sonucu tarafından belirtilen dosyaya çıkarır 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

Şifre çözme aynı şekilde işlenebilir; CreateDecryptor yerine kullanın CreateEncryptor .Decryption can be handled in the same way; use CreateDecryptor instead of CreateEncryptor. Dosyayı şifrelemek için kullanılan aynı anahtar ( Key ) ve başlatma vektörü ( IV ), şifresini çözmek için kullanılmalıdır.The same key (Key) and initialization vector (IV) used to encrypt the file must be used to decrypt it.

Açıklamalar

Bu algoritma 64 bitin anahtar uzunluğunu destekler.This algorithm supports a key length of 64 bits.

Önemli

Daha yeni bir simetrik şifreleme algoritması, Gelişmiş Şifreleme Standardı (AES) kullanılabilir.A newer symmetric encryption algorithm, Advanced Encryption Standard (AES), is available. Sınıfı Aes yerine sınıfını kullanmayı düşünün DES .Consider using the Aes class instead of the DES class. DESYalnızca eski uygulamalarla ve verilerle uyumluluk için kullanın.Use DES only for compatibility with legacy applications and data.

Oluşturucular

DESCryptoServiceProvider()

DESCryptoServiceProvider sınıfının yeni bir örneğini başlatır.Initializes a new instance of the DESCryptoServiceProvider class.

Alanlar

BlockSizeValue

Şifreleme işleminin bit cinsinden blok boyutunu temsil eder.Represents the block size, in bits, of the cryptographic operation.

(Devralındığı yer: SymmetricAlgorithm)
FeedbackSizeValue

Şifreleme işleminin bit cinsinden geri bildirim boyutunu temsil eder.Represents the feedback size, in bits, of the cryptographic operation.

(Devralındığı yer: SymmetricAlgorithm)
IVValue

Simetrik algoritma için başlatma vektörünü () temsil eder IV .Represents the initialization vector (IV) for the symmetric algorithm.

(Devralındığı yer: SymmetricAlgorithm)
KeySizeValue

Simetrik algoritma tarafından kullanılan gizli anahtarın bit cinsinden boyutunu temsil eder.Represents the size, in bits, of the secret key used by the symmetric algorithm.

(Devralındığı yer: SymmetricAlgorithm)
KeyValue

Simetrik algoritma için gizli anahtarı temsil eder.Represents the secret key for the symmetric algorithm.

(Devralındığı yer: SymmetricAlgorithm)
LegalBlockSizesValue

Simetrik algoritma tarafından desteklenen blok boyutlarını bit cinsinden belirtir.Specifies the block sizes, in bits, that are supported by the symmetric algorithm.

(Devralındığı yer: SymmetricAlgorithm)
LegalKeySizesValue

Simetrik algoritma tarafından desteklenen bit cinsinden anahtar boyutlarını belirtir.Specifies the key sizes, in bits, that are supported by the symmetric algorithm.

(Devralındığı yer: SymmetricAlgorithm)
ModeValue

Simetrik algoritmada kullanılan şifreleme modunu temsil eder.Represents the cipher mode used in the symmetric algorithm.

(Devralındığı yer: SymmetricAlgorithm)
PaddingValue

Simetrik algoritmada kullanılan doldurma modunu temsil eder.Represents the padding mode used in the symmetric algorithm.

(Devralındığı yer: SymmetricAlgorithm)

Özellikler

BlockSize

Şifreleme işleminin blok boyutunu bit cinsinden alır veya ayarlar.Gets or sets the block size, in bits, of the cryptographic operation.

(Devralındığı yer: SymmetricAlgorithm)
FeedbackSize

Şifre geri bildirimi (CFB) ve çıkış geri bildirimi (OFB) şifreleme modlarında şifreleme işleminin geri bildirim boyutunu bit cinsinden alır veya ayarlar.Gets or sets the feedback size, in bits, of the cryptographic operation for the Cipher Feedback (CFB) and Output Feedback (OFB) cipher modes.

(Devralındığı yer: SymmetricAlgorithm)
IV

Simetrik algoritma için başlatma vektörünü () alır veya ayarlar IV .Gets or sets the initialization vector (IV) for the symmetric algorithm.

(Devralındığı yer: SymmetricAlgorithm)
Key

Veri şifreleme standardı () algoritması için gizli anahtarı alır veya ayarlar DES .Gets or sets the secret key for the Data Encryption Standard (DES) algorithm.

(Devralındığı yer: DES)
KeySize

Simetrik algoritma tarafından kullanılan gizli anahtarın bit cinsinden boyutunu alır veya ayarlar.Gets or sets the size, in bits, of the secret key used by the symmetric algorithm.

(Devralındığı yer: SymmetricAlgorithm)
LegalBlockSizes

Simetrik algoritma tarafından desteklenen blok boyutlarını bit cinsinden alır.Gets the block sizes, in bits, that are supported by the symmetric algorithm.

(Devralındığı yer: SymmetricAlgorithm)
LegalKeySizes

Simetrik algoritma tarafından desteklenen bit cinsinden anahtar boyutlarını alır.Gets the key sizes, in bits, that are supported by the symmetric algorithm.

(Devralındığı yer: SymmetricAlgorithm)
Mode

Simetrik algoritmanın işlem modunu alır veya ayarlar.Gets or sets the mode for operation of the symmetric algorithm.

(Devralındığı yer: SymmetricAlgorithm)
Padding

Simetrik algoritmada kullanılan doldurma modunu alır veya ayarlar.Gets or sets the padding mode used in the symmetric algorithm.

(Devralındığı yer: SymmetricAlgorithm)

Yöntemler

Clear()

Sınıfı tarafından kullanılan tüm kaynakları serbest bırakır SymmetricAlgorithm .Releases all resources used by the SymmetricAlgorithm class.

(Devralındığı yer: SymmetricAlgorithm)
CreateDecryptor()

Geçerli Key özellik ve başlatma vektörü () ile simetrik bir şifre çözücü nesnesi oluşturur IV .Creates a symmetric decryptor object with the current Key property and initialization vector (IV).

CreateDecryptor()

Geçerli Key özellik ve başlatma vektörü () ile simetrik bir şifre çözücü nesnesi oluşturur IV .Creates a symmetric decryptor object with the current Key property and initialization vector (IV).

(Devralındığı yer: SymmetricAlgorithm)
CreateDecryptor(Byte[], Byte[])

DESBelirtilen anahtar ( Key ) ve başlatma vektörü () Ile simetrik veri şifreleme standardı () şifre çözücü nesnesi oluşturur IV .Creates a symmetric Data Encryption Standard (DES) decryptor object with the specified key (Key) and initialization vector (IV).

CreateEncryptor()

Geçerli Key özellik ve başlatma vektörü () ile simetrik bir Şifreleyici nesnesi oluşturur IV .Creates a symmetric encryptor object with the current Key property and initialization vector (IV).

CreateEncryptor()

Geçerli Key özellik ve başlatma vektörü () ile simetrik bir Şifreleyici nesnesi oluşturur IV .Creates a symmetric encryptor object with the current Key property and initialization vector (IV).

(Devralındığı yer: SymmetricAlgorithm)
CreateEncryptor(Byte[], Byte[])

DESBelirtilen anahtar ( Key ) ve başlatma vektörü () ile bir simetrik veri şifreleme standardı () Şifreleyici nesnesi oluşturur IV .Creates a symmetric Data Encryption Standard (DES) encryptor object with the specified key (Key) and initialization vector (IV).

Dispose()

SymmetricAlgorithm sınıfının geçerli örneği tarafından kullanılan tüm kaynakları serbest bırakır.Releases all resources used by the current instance of the SymmetricAlgorithm class.

(Devralındığı yer: SymmetricAlgorithm)
Dispose(Boolean)

SymmetricAlgorithm tarafından kullanılan yönetilmeyen kaynakları serbest bırakır ve yönetilen kaynakları isteğe bağlı olarak serbest bırakır.Releases the unmanaged resources used by the SymmetricAlgorithm and optionally releases the managed resources.

(Devralındığı yer: SymmetricAlgorithm)
Equals(Object)

Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler.Determines whether the specified object is equal to the current object.

(Devralındığı yer: Object)
GenerateIV()

Algoritma için kullanılacak rastgele bir başlatma vektörü ( IV ) oluşturur.Generates a random initialization vector (IV) to use for the algorithm.

GenerateKey()

Algoritma için kullanılacak rastgele bir anahtar ( Key ) oluşturur.Generates a random key (Key) to be used for the algorithm.

GetHashCode()

Varsayılan karma işlevi olarak işlev görür.Serves as the default hash function.

(Devralındığı yer: Object)
GetType()

TypeGeçerli örneği alır.Gets the Type of the current instance.

(Devralındığı yer: Object)
MemberwiseClone()

Geçerli bir basit kopyasını oluşturur Object .Creates a shallow copy of the current Object.

(Devralındığı yer: Object)
ToString()

Geçerli nesneyi temsil eden dizeyi döndürür.Returns a string that represents the current object.

(Devralındığı yer: Object)
ValidKeySize(Int32)

Belirtilen anahtar boyutunun geçerli algoritma için geçerli olup olmadığını belirler.Determines whether the specified key size is valid for the current algorithm.

(Devralındığı yer: SymmetricAlgorithm)

Belirtik Arabirim Kullanımları

IDisposable.Dispose()

Bu API, ürün altyapısını destekler ve doğrudan kodunuzdan kullanıma yönelik değildir.

SymmetricAlgorithm tarafından kullanılan yönetilmeyen kaynakları serbest bırakır ve yönetilen kaynakları isteğe bağlı olarak serbest bırakır.Releases the unmanaged resources used by the SymmetricAlgorithm and optionally releases the managed resources.

(Devralındığı yer: SymmetricAlgorithm)

Şunlara uygulanır