CryptoProvider.BlockSize 속성

정의

암호화 블록 크기를 바이트 단위로 가져옵니다.

public:
 property int BlockSize { int get(); };
public int BlockSize { get; }
member this.BlockSize : int
Public ReadOnly Property BlockSize As Integer

속성 값

암호화 블록 크기(바이트)입니다. AES(Advanced Encryption Standard)의 기본 블록 크기는 8입니다.

예제

다음 예제에서는 암호화된 텍스트 데이터로 텍스트 지우기 데이터를 변환할 때 이 속성을 사용하는 BlockSize 방법을 보여 있습니다.

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.")

설명

전달된 Encrypt 버퍼 및 DecryptcipherText 버퍼의 길이는 clearText n*BlockSize 바이트여야 합니다. 여기서 'n'은 1보다 크거나 같은 정수입니다.

false경우 CanMergeBlocks 전달된 버퍼는 전달된 EncryptDecrypt버퍼와 길이가 같아야 합니다.

이 경우 CanMergeBlocks 전달되는 버퍼는 전달된 EncryptDecrypt 버퍼와 다른 길이일 수 있습니다(모든 버퍼 크기는 항상 길이가 바이트의 배수 BlockSize 여야 합니다true).

BlockSize 1 중 1은 암호화가 스트림 암호임을 나타내고BlockSize, 2 이상은 블록 암호화를 나타냅니다.

적용 대상