ISpanAuthenticatedEncryptor.Encrypt<TWriter> 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
加密並認證一段明文資料,並將結果寫入緩衝區寫入器。
public void Encrypt<TWriter>(ReadOnlySpan<byte> plaintext, ReadOnlySpan<byte> additionalAuthenticatedData, ref TWriter destination) where TWriter : System.Buffers.IBufferWriter<byte>, allows ref struct;
abstract member Encrypt : ReadOnlySpan<byte> * ReadOnlySpan<byte> * 'Writer -> unit (requires 'Writer :> System.Buffers.IBufferWriter<byte>)
Public Sub Encrypt(Of TWriter As IBufferWriter(Of Byte)) (plaintext As ReadOnlySpan(Of Byte), additionalAuthenticatedData As ReadOnlySpan(Of Byte), ByRef destination As TWriter)
類型參數
- TWriter
用來寫入密文的緩衝區寫入器類型。
參數
- plaintext
- ReadOnlySpan<Byte>
明文要加密。 此輸入長度可為零位元組。
- additionalAuthenticatedData
- ReadOnlySpan<Byte>
這段資料不會包含在返回的密文中,但仍會被認證標籤涵蓋。 此輸入長度可為零位元組。 在對應的呼叫 Decrypt<TWriter>(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, TWriter)中必須指定相同的 AAD。
- destination
- TWriter
密文(包括認證標籤)將寫入的緩衝區寫入器。
備註
此方法提供了優化的串流替代方案。Encrypt(ArraySegment<Byte>, ArraySegment<Byte>) 密文不需分配中間緩衝區,而是直接寫入所提供的緩衝區寫入器,這能提升效能並減輕記憶體配置壓力。 緩衝區寫入器會依照寫入的位元組總數來前進。