public bool VerifyHash(byte[] hash, string hashAlgOid, byte[] sig)
        {
            IDT.ThrowInvalidArgumentConditional(null == hash || 0 == hash.Length, "hash");
            IDT.ThrowInvalidArgumentConditional(String.IsNullOrEmpty(hashAlgOid), "hashAlgOid");
            IDT.ThrowInvalidArgumentConditional(null == sig || 0 == sig.Length, "sig");
            bool verified = false;

            using (HGlobalSafeHandle pHash = HGlobalSafeHandle.Construct(hash.Length))
            {
                using (HGlobalSafeHandle pHashAlgOid = HGlobalSafeHandle.Construct(hashAlgOid))
                {
                    Marshal.Copy(hash, 0, pHash.DangerousGetHandle(), hash.Length);
                    int status = 0;
                    using (HGlobalSafeHandle pSig = HGlobalSafeHandle.Construct(sig.Length))
                    {
                        Marshal.Copy(sig, 0, pSig.DangerousGetHandle(), sig.Length);

                        status = CardSpaceSelector.GetShim().m_csShimVerifyHash(m_cryptoHandle.InternalHandle,
                                                                                hash.Length,
                                                                                pHash,
                                                                                pHashAlgOid,
                                                                                sig.Length,
                                                                                pSig,
                                                                                out verified);
                    }
                    if (0 != status)
                    {
                        ExceptionHelper.ThrowIfCardSpaceException(status);
                        throw IDT.ThrowHelperError(new Win32Exception(status));
                    }
                }
            }

            return(verified);
        }
        public byte[] Decrypt(byte[] inData, bool fAOEP)
        {
            GlobalAllocSafeHandle pOutData = null;
            int cbOutData = 0;

            byte[] outData;
            IDT.ThrowInvalidArgumentConditional(null == inData, "indata");
            using (HGlobalSafeHandle pInData = HGlobalSafeHandle.Construct(inData.Length))
            {
                Marshal.Copy(inData, 0, pInData.DangerousGetHandle(), inData.Length);
                int status = CardSpaceSelector.GetShim().m_csShimDecrypt(m_cryptoHandle.InternalHandle,
                                                                         fAOEP,
                                                                         inData.Length,
                                                                         pInData,
                                                                         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);
                }
            }

            return(outData);
        }
        //
        // Parameters:
        //  target     - The target of the token being described.
        //  parameters - describes the type of token required by the target.
        //
        public CardSpacePolicyElement(XmlElement target, XmlElement issuer, Collection <XmlElement> parameters, Uri privacyNoticeLink, int privacyNoticeVersion, bool isManagedIssuer)
        {
            //
            // Ensure that if a version is specified( value != 0 ), that a valid url is specified.
            //
            IDT.ThrowInvalidArgumentConditional(0 == privacyNoticeVersion && null != privacyNoticeLink, "privacyNoticeVersion");
            IDT.ThrowInvalidArgumentConditional(0 != privacyNoticeVersion && null == privacyNoticeLink, "privacyNoticeLink");

            m_target              = target;
            m_issuer              = issuer;
            m_parameters          = parameters;
            m_policyNoticeLink    = privacyNoticeLink;
            m_policyNoticeVersion = privacyNoticeVersion;
            m_isManagedIssuer     = isManagedIssuer;
        }
        public byte[] SignHash(byte[] hash, string hashAlgOid)
        {
            IDT.ThrowInvalidArgumentConditional(null == hash || 0 == hash.Length, "hash");
            IDT.ThrowInvalidArgumentConditional(String.IsNullOrEmpty(hashAlgOid), "hashAlgOid");
            int cbSig = 0;
            GlobalAllocSafeHandle pSig = null;

            byte[] sig;
            using (HGlobalSafeHandle pHash = HGlobalSafeHandle.Construct(hash.Length))
            {
                using (HGlobalSafeHandle pHashAlgOid = HGlobalSafeHandle.Construct(hashAlgOid))
                {
                    Marshal.Copy(hash, 0, pHash.DangerousGetHandle(), hash.Length);

                    RuntimeHelpers.PrepareConstrainedRegions();
                    int status = CardSpaceSelector.GetShim().m_csShimSignHash(m_cryptoHandle.InternalHandle,
                                                                              hash.Length,
                                                                              pHash,
                                                                              pHashAlgOid,
                                                                              out cbSig,
                                                                              out pSig);

                    if (0 != status)
                    {
                        ExceptionHelper.ThrowIfCardSpaceException(status);
                        throw IDT.ThrowHelperError(new Win32Exception(status));
                    }
                    pSig.Length = cbSig;
                    sig         = DiagnosticUtility.Utility.AllocateByteArray(pSig.Length);
                    using (pSig)
                    {
                        Marshal.Copy(pSig.DangerousGetHandle(), sig, 0, pSig.Length);
                    }
                }
            }

            return(sig);
        }