/// <summary> /// Encrypts message /// </summary> public byte[] EncryptMessage(SecurityContext context, byte[] message) { // parameters validation if (context == null) { throw new ArgumentNullException("context"); } if (message == null) { throw new ArgumentNullException("message"); } // prepare buffers SecurityBuffers inputBuffers = new SecurityBuffers(2); inputBuffers.SetBuffer(0, (int)SSPINative.SECBUFFER_DATA, message); inputBuffers.SetBuffer(1, (int)SSPINative.SECBUFFER_TOKEN, context.SecurityTrailer); // encrypt message Int64 contextHandle = context.Handle; int error = SSPINative.EncryptMessage( ref contextHandle, 0, inputBuffers, 0); if (error < 0) { throw new SSPIException(error, "Could not encrypt message"); } // get encrypted data and trailer byte[] encrypted = inputBuffers.GetBuffer(0); byte[] trailer = inputBuffers.GetBuffer(1); inputBuffers.Dispose(); // create encrypted buffer return(CreateEncryptedBuffer(encrypted, trailer)); }