Example #1
0
        /// <summary>
        /// The decrypted data will start header bytes from the start of
        /// encryptedContent array.
        /// </summary>
        internal unsafe void DecryptInPlace(byte[] encryptedContent, out int dataStartOffset, out int dataLen)
        {
            ThrowIfDisposed();
            dataStartOffset = StreamSizes.header;
            dataLen         = 0;

            byte[] emptyBuffer1 = new byte[0];
            byte[] emptyBuffer2 = new byte[0];
            byte[] emptyBuffer3 = new byte[0];

            SecurityBuffer[] securityBuffer = new SecurityBuffer[4];
            securityBuffer[0] = new SecurityBuffer(encryptedContent, 0, encryptedContent.Length, BufferType.Data);
            securityBuffer[1] = new SecurityBuffer(emptyBuffer1, BufferType.Empty);
            securityBuffer[2] = new SecurityBuffer(emptyBuffer2, BufferType.Empty);
            securityBuffer[3] = new SecurityBuffer(emptyBuffer3, BufferType.Empty);

            int errorCode = SspiWrapper.DecryptMessage(this.securityContext, securityBuffer, 0, false);

            if (errorCode != 0)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(errorCode));
            }

            for (int i = 0; i < securityBuffer.Length; ++i)
            {
                if (securityBuffer[i].type == BufferType.Data)
                {
                    dataLen = securityBuffer[i].size;
                    return;
                }
            }

            OnBadData();
        }
        internal void DecryptInPlace(byte[] encryptedContent, out int dataStartOffset, out int dataLen)
        {
            this.ThrowIfDisposed();
            dataStartOffset = this.StreamSizes.header;
            dataLen         = 0;
            byte[]           data    = new byte[0];
            byte[]           buffer2 = new byte[0];
            byte[]           buffer3 = new byte[0];
            SecurityBuffer[] input   = new SecurityBuffer[] { new SecurityBuffer(encryptedContent, 0, encryptedContent.Length, System.IdentityModel.BufferType.Data), new SecurityBuffer(data, System.IdentityModel.BufferType.Empty), new SecurityBuffer(buffer2, System.IdentityModel.BufferType.Empty), new SecurityBuffer(buffer3, System.IdentityModel.BufferType.Empty) };
            int error = SspiWrapper.DecryptMessage(this.securityContext, input, 0, false);

            if (error != 0)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(error));
            }
            for (int i = 0; i < input.Length; i++)
            {
                if (input[i].type == System.IdentityModel.BufferType.Data)
                {
                    dataLen = input[i].size;
                    return;
                }
            }
            this.OnBadData();
        }
        public byte[] Decrypt(byte[] encryptedContent)
        {
            if (encryptedContent == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("encryptedContent");
            }
            ThrowIfDisposed();

            SecurityBuffer[] securityBuffer = new SecurityBuffer[2];
            securityBuffer[0] = new SecurityBuffer(encryptedContent, 0, encryptedContent.Length, BufferType.Stream);
            securityBuffer[1] = new SecurityBuffer(0, BufferType.Data);
            int errorCode = SspiWrapper.DecryptMessage(this.securityContext, securityBuffer, 0, true);

            if (errorCode != 0)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(errorCode));
            }

            for (int i = 0; i < securityBuffer.Length; ++i)
            {
                if (securityBuffer[i].type == BufferType.Data)
                {
                    return(securityBuffer[i].token);
                }
            }
            OnBadData();
            return(null);
        }
Example #4
0
        public byte[] Decrypt(byte[] encryptedContent)
        {
            if (encryptedContent == null)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("encryptedContent");
            }
            this.ThrowIfDisposed();
            SecurityBuffer[] input = new SecurityBuffer[] { new SecurityBuffer(encryptedContent, 0, encryptedContent.Length, BufferType.Stream), new SecurityBuffer(0, BufferType.Data) };
            int error = SspiWrapper.DecryptMessage(this.securityContext, input, 0, true);

            if (error != 0)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(error));
            }
            for (int i = 0; i < input.Length; i++)
            {
                if (input[i].type == BufferType.Data)
                {
                    return(input[i].token);
                }
            }
            this.OnBadData();
            return(null);
        }