Пример #1
0
        /// <summary>
        /// Verifies the signature of a message
        /// </summary>
        public void VerifySignature(SecurityContext context, byte[] message, byte[] signature)
        {
            // parameters validation
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (signature == null)
            {
                throw new ArgumentNullException("signature");
            }

            // prepare buffers
            SecurityBuffers inputBuffers = new SecurityBuffers(2);

            inputBuffers.SetBuffer(0, (int)SSPINative.SECBUFFER_DATA, message);
            inputBuffers.SetBuffer(1, (int)SSPINative.SECBUFFER_TOKEN, signature);

            // verify signature
            Int64 contextHandle = context.Handle;
            int   error         = SSPINative.VerifySignature(
                ref contextHandle,
                inputBuffers,
                0,
                0);

            if (error < 0)
            {
                switch (error)
                {
                case SSPINative.SEC_E_MESSAGE_ALTERED:
                    throw new SSPIException(error, "The message or signature supplied for verification has been altered");

                case SSPINative.SEC_E_OUT_OF_SEQUENCE:
                    throw new SSPIException(error, "The message supplied for verification is out of sequence");

                default:
                    throw new SSPIException(error, "Could not verify message signature");
                }
                ;
            }
        }