public override int Transform(byte[] input, int inputOffset, int count, byte[] output, int outputOffset) { Debug.Assert(input != null); Debug.Assert(inputOffset >= 0); Debug.Assert(count > 0); Debug.Assert((count % BlockSizeInBytes) == 0); Debug.Assert(input.Length - inputOffset >= count); Debug.Assert(output != null); Debug.Assert(outputOffset >= 0); Debug.Assert(output.Length - outputOffset >= count); int numBytesWritten; if (_encrypting) { numBytesWritten = BCryptNative.BCryptEncrypt(_hKey, input, inputOffset, count, _currentIv, output, outputOffset, output.Length - outputOffset); } else { numBytesWritten = BCryptNative.BCryptDecrypt(_hKey, input, inputOffset, count, _currentIv, output, outputOffset, output.Length - outputOffset); } if (numBytesWritten != count) { // CNG gives us no way to tell BCryptDecrypt() that we're decrypting the final block, nor is it performing any // padding /depadding for us. So there's no excuse for a provider to hold back output for "future calls." Though // this isn't technically our problem to detect, we might as well detect it now for easier diagnosis. throw new CryptographicException(SR.Cryptography_UnexpectedTransformTruncation); } return(numBytesWritten); }