示例#1
0
        //
        // Summary:
        //  Implements the HashFinal method of the KeyedHashAlgorithm class by calling the InfoCard native client.
        //
        protected override byte[] HashFinal()
        {
            byte[] outData   = null;
            int    cbOutData = 0;

            IDT.DebugAssert(null != m_cachedBlock, "null cached block");

            HGlobalSafeHandle     pInData  = null;
            GlobalAllocSafeHandle pOutData = null;

            try
            {
                if (null != m_cachedBlock)
                {
                    if (0 != m_cachedBlock.Length)
                    {
                        pInData = HGlobalSafeHandle.Construct(m_cachedBlock.Length);
                        Marshal.Copy(m_cachedBlock, 0, pInData.DangerousGetHandle(), m_cachedBlock.Length);
                    }

                    int status = CardSpaceSelector.GetShim().m_csShimHashFinal(m_cryptoHandle.InternalHandle,
                                                                               m_cachedBlock.Length,
                                                                               null != pInData ? pInData : HGlobalSafeHandle.Construct(),
                                                                               out cbOutData,
                                                                               out pOutData);
                    if (0 != status)
                    {
                        ExceptionHelper.ThrowIfCardSpaceException(status);
                        throw IDT.ThrowHelperError(new Win32Exception(status));
                    }
                    pOutData.Length = cbOutData;
                    outData         = DiagnosticUtility.Utility.AllocateByteArray(pOutData.Length);
                    using (pOutData)
                    {
                        Marshal.Copy(pOutData.DangerousGetHandle(), outData, 0, pOutData.Length);
                    }
                }
            }
            finally
            {
                if (null != pInData)
                {
                    pInData.Dispose();
                }
                Array.Clear(m_cachedBlock, 0, m_cachedBlock.Length);
                m_cachedBlock = null;
            }

            return(outData);
        }
示例#2
0
        //
        // Summary:
        //  Implements the HashCore method of the KeyedHashAlgorithm class by calling the InfoCard native client.
        //
        // Parameters:
        //  array   - the bytes to hash.
        //  ibStart - the index in the array from which to begin hashing.
        //  cbSize  - the number of bytes after the starting index to hash.
        //
        protected override void HashCore(byte[] array, int ibStart, int cbSize)
        {
            //
            // will cache one block and call TransformBlock on the previous block.
            //
            if (null != m_cachedBlock)
            {
                HGlobalSafeHandle pInData = null;
                try
                {
                    if (0 != m_cachedBlock.Length)
                    {
                        pInData = HGlobalSafeHandle.Construct(m_cachedBlock.Length);
                        Marshal.Copy(m_cachedBlock, 0, pInData.DangerousGetHandle(), m_cachedBlock.Length);
                    }

                    int status = CardSpaceSelector.GetShim().m_csShimHashCore(m_cryptoHandle.InternalHandle,
                                                                              m_cachedBlock.Length,
                                                                              null != pInData ? pInData : HGlobalSafeHandle.Construct());

                    if (0 != status)
                    {
                        ExceptionHelper.ThrowIfCardSpaceException(status);
                        throw IDT.ThrowHelperError(new Win32Exception(status));
                    }
                }
                finally
                {
                    if (null != pInData)
                    {
                        pInData.Dispose();
                    }
                }
            }

            //
            // Cache the current block.
            //
            if (null != m_cachedBlock)
            {
                Array.Clear(m_cachedBlock, 0, m_cachedBlock.Length);
            }
            m_cachedBlock = DiagnosticUtility.Utility.AllocateByteArray(cbSize);
            Array.Copy(array, ibStart, m_cachedBlock, 0, cbSize);

            return;
        }
        protected override byte[] HashFinal()
        {
            byte[]                destination = null;
            int                   cbOutData   = 0;
            HGlobalSafeHandle     handle      = null;
            GlobalAllocSafeHandle pOutData    = null;

            try
            {
                if (this.m_cachedBlock == null)
                {
                    return(destination);
                }
                if (this.m_cachedBlock.Length != 0)
                {
                    handle = HGlobalSafeHandle.Construct(this.m_cachedBlock.Length);
                    Marshal.Copy(this.m_cachedBlock, 0, handle.DangerousGetHandle(), this.m_cachedBlock.Length);
                }
                int status = CardSpaceSelector.GetShim().m_csShimHashFinal(this.m_cryptoHandle.InternalHandle, this.m_cachedBlock.Length, (handle != null) ? handle : HGlobalSafeHandle.Construct(), out cbOutData, out pOutData);
                if (status != 0)
                {
                    ExceptionHelper.ThrowIfCardSpaceException(status);
                    throw InfoCardTrace.ThrowHelperError(new Win32Exception(status));
                }
                pOutData.Length = cbOutData;
                destination     = DiagnosticUtility.Utility.AllocateByteArray(pOutData.Length);
                using (pOutData)
                {
                    Marshal.Copy(pOutData.DangerousGetHandle(), destination, 0, pOutData.Length);
                }
            }
            finally
            {
                if (handle != null)
                {
                    handle.Dispose();
                }
                Array.Clear(this.m_cachedBlock, 0, this.m_cachedBlock.Length);
                this.m_cachedBlock = null;
            }
            return(destination);
        }
        private void Dispose(bool disposing)
        {
            if (disposing)
            {
                GC.SuppressFinalize(this);
            }

            if (null != m_chain)
            {
                foreach (InternalPolicyElement element in m_chain)
                {
                    if (null != element)
                    {
                        element.Dispose();
                    }
                }
                m_chain = null;
            }

            if (null != m_nativeChain)
            {
                m_nativeChain.Dispose();
            }
        }