static SECURITY_STATUS nla_encrypt(rdpNla* nla, SecBuffer* buffer, size_t headerLength)
{
	SECURITY_STATUS status = SEC_E_INVALID_PARAMETER;
	SecBuffer Buffers[2];
	SecBufferDesc Message;

	if (!nla || !nla->table)
	{
		WLog_ERR(TAG, "[%s] nla->table=%p->%p", __FUNCTION__, nla, nla ? nla->table : NULL);
		return SEC_E_INVALID_PARAMETER;
	}
	if (!nla->table->EncryptMessage)
	{
		WLog_ERR(TAG, "[%s] EncryptMessage=%p", __FUNCTION__, nla->table->EncryptMessage);
		return ERROR_INTERNAL_ERROR;
	}

	if (!buffer || (headerLength > buffer->cbBuffer))
	{
		return SEC_E_INVALID_PARAMETER;
	}

	Message.cBuffers = 2;
	Buffers[0].BufferType = SECBUFFER_TOKEN; /* Signature */
	Buffers[0].cbBuffer = (ULONG)headerLength;
	Buffers[0].pvBuffer = &((BYTE*)buffer->pvBuffer)[0];

	Buffers[1].BufferType = SECBUFFER_DATA;
	Buffers[1].cbBuffer = (ULONG)(buffer->cbBuffer - headerLength);
	Buffers[1].pvBuffer = &((BYTE*)buffer->pvBuffer)[headerLength];

	Message.pBuffers = Buffers;
	Message.ulVersion = SECBUFFER_VERSION;
	status = nla->table->EncryptMessage(&nla->context, 0, &Message, nla->sendSeqNum++);

	if (status != SEC_E_OK)
	{
		WLog_ERR(TAG, "EncryptMessage status %s [0x%08" PRIX32 "]", GetSecurityStatusString(status),
		         status);
		return status;
	}

	if ((Message.cBuffers == 2) && (Buffers[0].cbBuffer < nla->ContextSizes.cbSecurityTrailer))
	{
		/* IMPORTANT: EncryptMessage may not use all the signature space, so we need to shrink the
		 * excess between the buffers */
		MoveMemory(((BYTE*)Buffers[0].pvBuffer) + Buffers[0].cbBuffer, Buffers[1].pvBuffer,
		           Buffers[1].cbBuffer);
		buffer->cbBuffer = Buffers[0].cbBuffer + Buffers[1].cbBuffer;
	}

	return status;
}
static SECURITY_STATUS nla_encrypt(rdpNla* nla, SecBuffer* buffer, size_t headerLength)
{
	SECURITY_STATUS status = SEC_E_INVALID_PARAMETER;
	SecBuffer Buffers[2];
	SecBufferDesc Message;

	if (!nla || !nla->table)
	{
		WLog_ERR(TAG, "[%s] nla->table=%p->%p", __FUNCTION__, nla, nla ? nla->table : NULL);
		return SEC_E_INVALID_PARAMETER;
	}
	if (!nla->table->EncryptMessage)
	{
		WLog_ERR(TAG, "[%s] EncryptMessage=%p", __FUNCTION__, nla->table->EncryptMessage);
		return ERROR_INTERNAL_ERROR;
	}

	if (!buffer || (headerLength > buffer->cbBuffer))
	{
		return SEC_E_INVALID_PARAMETER;
	}

	Message.cBuffers = 2;
	Buffers[0].BufferType = SECBUFFER_TOKEN;  
	Buffers[0].cbBuffer = (ULONG)headerLength;
	Buffers[0].pvBuffer = &((BYTE*)buffer->pvBuffer)[0];

	Buffers[1].BufferType = SECBUFFER_DATA;
	Buffers[1].cbBuffer = (ULONG)(buffer->cbBuffer - headerLength);
	Buffers[1].pvBuffer = &((BYTE*)buffer->pvBuffer)[headerLength];

	Message.pBuffers = Buffers;
	Message.ulVersion = SECBUFFER_VERSION;
	status = nla->table->EncryptMessage(&nla->context, 0, &Message, nla->sendSeqNum++);

	if (status != SEC_E_OK)
	{
		WLog_ERR(TAG, "EncryptMessage status %s [0x%08" PRIX32 "]", GetSecurityStatusString(status),
		         status);
		return status;
	}

	if ((Message.cBuffers == 2) && (Buffers[0].cbBuffer < nla->ContextSizes.cbSecurityTrailer))
	{
		 
		MoveMemory(((BYTE*)Buffers[0].pvBuffer) + Buffers[0].cbBuffer, Buffers[1].pvBuffer,
		           Buffers[1].cbBuffer);
		buffer->cbBuffer = Buffers[0].cbBuffer + Buffers[1].cbBuffer;
	}

	return status;
}