public void FlushFinalBlock()
{
if (_finalBlockTransformed)
throw new NotSupportedException(SR.Cryptography_CryptoStream_FlushFinalBlockTwice);
// We have to process the last block here. First, we have the final block in _InputBuffer, so transform it
byte[] finalBytes = _transform.TransformFinalBlock(_inputBuffer, 0, _inputBufferIndex);
_finalBlockTransformed = true;
// Now, write out anything sitting in the _OutputBuffer...
if (_canWrite && _outputBufferIndex > 0)
{
_stream.Write(_outputBuffer, 0, _outputBufferIndex);
_outputBufferIndex = 0;
}
// Write out finalBytes
if (_canWrite)
_stream.Write(finalBytes, 0, finalBytes.Length);
// If the inner stream is a CryptoStream, then we want to call FlushFinalBlock on it too, otherwise just Flush.
CryptoStream innerCryptoStream = _stream as CryptoStream;
if (innerCryptoStream != null)
{
if (!innerCryptoStream.HasFlushedFinalBlock)
{
innerCryptoStream.FlushFinalBlock();
}
}
else
{
_stream.Flush();
}
// zeroize plain text material before returning
if (_inputBuffer != null)
Array.Clear(_inputBuffer, 0, _inputBuffer.Length);
if (_outputBuffer != null)
Array.Clear(_outputBuffer, 0, _outputBuffer.Length);
return;
}