CryptoProvider.BlockSize Özellik
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Şifre bloğu boyutunu bayt cinsinden alır.
public:
property int BlockSize { int get(); };
public int BlockSize { get; }
member this.BlockSize : int
Public ReadOnly Property BlockSize As Integer
Özellik Değeri
Bayt cinsinden şifre bloğu boyutu. Gelişmiş Şifreleme Standardı (AES) için varsayılan blok boyutu 8'dir.
Örnekler
Aşağıdaki örnekte, düz metin verilerini şifrelenmiş metin verilerine BlockSize dönüştürmek için özelliğinin nasıl kullanılacağı gösterilmektedir.
WriteStatus(" Binding the author's UseLicense and");
WriteStatus(" obtaining the CryptoProvider.");
using (CryptoProvider cryptoProvider =
authorsUseLicense.Bind(_secureEnv))
{
WriteStatus(" Writing encrypted content.");
using (Stream clearTextStream =
File.OpenRead(contentFile) )
{
using (Stream cryptoTextStream =
File.OpenWrite(encryptedFile))
{
// Write the length of the source content file
// as the first four bytes of the encrypted file.
cryptoTextStream.Write(
BitConverter.GetBytes(clearTextStream.Length),
0, sizeof(Int32));
// Allocate clearText buffer.
byte[] clearTextBlock =
new byte[cryptoProvider.BlockSize];
// Encrypt clearText to cryptoText block by block.
for(;;)
{ // Read clearText block.
int readCount = ReliableRead(
clearTextStream,
clearTextBlock, 0 ,
cryptoProvider.BlockSize);
// readCount of zero is end of data.
if (readCount == 0) break; // for
// Encrypt clearText to cryptoText.
byte[] cryptoTextBlock =
cryptoProvider.Encrypt(clearTextBlock);
// Write cryptoText block.
cryptoTextStream.Write(cryptoTextBlock, 0,
cryptoTextBlock.Length);
}
WriteStatus(" Closing '" + encryptedFilename + "'.");
}// end:using (Stream cryptoTextStream =
}// end:using (Stream clearTextStream =
}// end:using (CryptoProvider cryptoProvider =
WriteStatus(" Done - Content encryption complete.");
WriteStatus(" Binding the author's UseLicense and")
WriteStatus(" obtaining the CryptoProvider.")
Using cryptoProvider As CryptoProvider = authorsUseLicense.Bind(_secureEnv)
WriteStatus(" Writing encrypted content.")
Using clearTextStream As Stream = File.OpenRead(contentFile)
Using cryptoTextStream As Stream = File.OpenWrite(encryptedFile)
' Write the length of the source content file
' as the first four bytes of the encrypted file.
Dim expression As Int32
cryptoTextStream.Write(BitConverter.GetBytes(clearTextStream.Length), 0, Len(expression))
' Allocate clearText buffer.
Dim clearTextBlock(cryptoProvider.BlockSize - 1) As Byte
' Encrypt clearText to cryptoText block by block.
Do
Dim readCount As Integer = ReliableRead(clearTextStream, clearTextBlock, 0, cryptoProvider.BlockSize)
' readCount of zero is end of data.
If readCount = 0 Then ' for
Exit Do
End If
' Encrypt clearText to cryptoText.
Dim cryptoTextBlock() As Byte = cryptoProvider.Encrypt(clearTextBlock)
' Write cryptoText block.
cryptoTextStream.Write(cryptoTextBlock, 0, cryptoTextBlock.Length)
Loop
WriteStatus(" Closing '" & encryptedFilename & "'.")
End Using ' end:using (Stream cryptoTextStream =
End Using ' end:using (Stream clearTextStream =
End Using ' end:using (CryptoProvider cryptoProvider =
WriteStatus(" Done - Content encryption complete.")
Açıklamalar
ve öğesine clearText
geçirilen Encrypt ve cipherText
Decrypt arabellekleri n*BlockSize bayt uzunluğunda olmalıdır; burada 'n' 1'den büyük veya buna eşit bir tamsayıdır.
ise CanMergeBlocks false
, öğesine geçirilen arabellekler, 'a Encrypt Decryptgeçirilen arabelleklerle aynı uzunlukta olmalıdır.
ise CanMergeBlocks true
, öğesine Encrypt geçirilen arabellekler, geçirilen Decrypt arabelleklerden farklı uzunlukta olabilir (tüm arabellek boyutları yine de her zaman bayt cinsinden bir kat BlockSize olmalıdır).
BlockSize 1'den biri, şifrenin bir akış şifresi olduğunu, 2 veya daha büyük bir BlockSize değeri ise blok şifrelemesini belirtir.