public void Unwrap(int messageLength, byte[] encryptedBuffer, out byte[] decryptedBuffer) { decryptedBuffer = null; WindowsAPI.SECURITY_HANDLE decryptionContext = _clientContextHandle; byte[] encryptedMessage = new byte[messageLength]; Array.Copy(encryptedBuffer, 0, encryptedMessage, 0, messageLength); WindowsAPI.MultipleSecBufferHelper[] secHelper = new WindowsAPI.MultipleSecBufferHelper[2]; secHelper[0] = new WindowsAPI.MultipleSecBufferHelper(encryptedMessage, WindowsAPI.SecBufferType.SECBUFFER_STREAM); secHelper[1] = new WindowsAPI.MultipleSecBufferHelper(null, WindowsAPI.SecBufferType.SECBUFFER_DATA); WindowsAPI.SecBufferDesc descBuffer = new WindowsAPI.SecBufferDesc(secHelper); try { uint encryptionQuality = 0; var ss = WindowsAPI.DecryptMessage(ref decryptionContext, ref descBuffer, 0, out encryptionQuality); if (ss != WindowsAPI.SEC_E_OK) { throw WindowsAPI.CreateException(ss, "DecryptMessage() failed!!!"); } decryptedBuffer = new byte[messageLength]; Array.Copy(descBuffer.GetSecBufferByteArray(), 0, decryptedBuffer, 0, messageLength); } finally { descBuffer.Dispose(); } }