internal SecBufferDesc(MultipleSecBufferHelper[] secBufferBytesArray)
        {
            if (secBufferBytesArray == null || secBufferBytesArray.Length == 0)
            {
                throw new ArgumentException("secBufferBytesArray cannot be null or 0 length");
            }

            ulVersion = (int)SecBufferType.SECBUFFER_VERSION;
            cBuffers = secBufferBytesArray.Length;

            //Allocate memory for SecBuffer Array....
            pBuffers = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SecBuffer)) * cBuffers);

            for (int Index = 0; Index < secBufferBytesArray.Length; Index++)
            {
                //Super hack: Now allocate memory for the individual SecBuffers
                //and just copy the bit values to the SecBuffer array!!!
                SecBuffer ThisSecBuffer = new SecBuffer(secBufferBytesArray[Index].Buffer,
                    secBufferBytesArray[Index].BufferType);

                //We will write out bits in the following order:
                //int cbBuffer;
                //int BufferType;
                //pvBuffer;
                //Note: that we won't be releasing the memory allocated by ThisSecBuffer until we
                //are disposed...
                int CurrentOffset = Index * Marshal.SizeOf(typeof(SecBuffer));
                Marshal.WriteInt32(pBuffers, CurrentOffset, ThisSecBuffer.cbBuffer);

                int length = CurrentOffset + Marshal.SizeOf(ThisSecBuffer.cbBuffer);
                Marshal.WriteInt32(pBuffers, length, ThisSecBuffer.BufferType);

                length = CurrentOffset + Marshal.SizeOf(ThisSecBuffer.cbBuffer) +
                         Marshal.SizeOf(ThisSecBuffer.BufferType);
                Marshal.WriteIntPtr(pBuffers, length, ThisSecBuffer.pvBuffer);
            }
        }
 public SecBufferDesc(byte[] secBufferBytes)
 {
     ulVersion = (int)SecBufferType.SECBUFFER_VERSION;
     cBuffers = 1;
     SecBuffer ThisSecBuffer = new SecBuffer(secBufferBytes);
     pBuffers = Marshal.AllocHGlobal(Marshal.SizeOf(ThisSecBuffer));
     Marshal.StructureToPtr(ThisSecBuffer, pBuffers, false);
 }