CryptoProvider.Encrypt(Byte[]) 메서드

정의

일반 텍스트를 암호화 텍스트로 암호화합니다.

public:
 cli::array <System::Byte> ^ Encrypt(cli::array <System::Byte> ^ clearText);
public byte[] Encrypt (byte[] clearText);
member this.Encrypt : byte[] -> byte[]
Public Function Encrypt (clearText As Byte()) As Byte()

매개 변수

clearText
Byte[]

암호화할 일반 텍스트 콘텐츠입니다.

반환

Byte[]

지정된 clearText의 암호화된 암호화 텍스트입니다.

예외

clearText가 null입니다.

암호화가 허용되지 않는 경우

예제

다음 예제에서는 사용 하는 방법의 Encrypt 암호화 된 텍스트 데이터에 일반 텍스트 데이터를 변환 하는 방법입니다.

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

설명

바이트 길이 clearText 버퍼 암호화의 배수 여야 합니다. BlockSize 속성입니다.

AES 블록 암호화를 사용 하는 디지털 권한 관리 됩니다. AES를 사용 하 여 블록 암호화 되며 독립적으로 동일한 암호화 텍스트 결과 생성 되는 두 개의 동일한 일반 텍스트 블록. 독립적인 블록 암호화에서 잠재적인 위협 요인을 암호 해독을 최소화 하려면 애플리케이션 압축을 동일한 일반 텍스트 블록이 암호화를 방지 하려면 같은 콘텐츠를 수정 하는 메서드를 사용 해야 합니다.

적용 대상

추가 정보