internal SignerInfo(SignedCms signedCms, System.Security.Cryptography.SafeLocalAllocHandle pbCmsgSignerInfo)
 {
     this.m_signedCms = signedCms;
     this.m_parentSignerInfo = null;
     this.m_encodedSignerInfo = null;
     this.m_pbCmsgSignerInfo = pbCmsgSignerInfo;
     this.m_cmsgSignerInfo = (System.Security.Cryptography.CAPI.CMSG_SIGNER_INFO) Marshal.PtrToStructure(pbCmsgSignerInfo.DangerousGetHandle(), typeof(System.Security.Cryptography.CAPI.CMSG_SIGNER_INFO));
 }
 private static void DisplayX509Certificate(System.Security.Cryptography.SafeCertContextHandle safeCertContext, IntPtr hwndParent)
 {
     System.Security.Cryptography.CAPI.CRYPTUI_VIEWCERTIFICATE_STRUCTW cryptui_viewcertificate_structw;
     if (safeCertContext.IsInvalid)
     {
         throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_InvalidHandle"), "safeCertContext");
     }
     int num = 0;
     cryptui_viewcertificate_structw = new System.Security.Cryptography.CAPI.CRYPTUI_VIEWCERTIFICATE_STRUCTW {
         dwSize = Marshal.SizeOf(cryptui_viewcertificate_structw),
         hwndParent = hwndParent,
         dwFlags = 0,
         szTitle = null,
         pCertContext = safeCertContext.DangerousGetHandle(),
         rgszPurposes = IntPtr.Zero,
         cPurposes = 0,
         pCryptProviderData = IntPtr.Zero,
         fpCryptProviderDataTrustedUsage = false,
         idxSigner = 0,
         idxCert = 0,
         fCounterSigner = false,
         idxCounterSigner = 0,
         cStores = 0,
         rghStores = IntPtr.Zero,
         cPropSheetPages = 0,
         rgPropSheetPages = IntPtr.Zero,
         nStartPage = 0
     };
     if (!System.Security.Cryptography.CAPI.CryptUIDlgViewCertificateW(cryptui_viewcertificate_structw, IntPtr.Zero))
     {
         num = Marshal.GetLastWin32Error();
     }
     if ((num != 0) && (num != 0x4c7))
     {
         throw new CryptographicException(Marshal.GetLastWin32Error());
     }
 }
 internal CryptographicAttributeObjectCollection(System.Security.Cryptography.SafeLocalAllocHandle pCryptAttributes) : this(pCryptAttributes.DangerousGetHandle())
 {
 }
 private static void RemoveCertificateFromStore(System.Security.Cryptography.SafeCertStoreHandle safeCertStoreHandle, System.Security.Cryptography.SafeCertContextHandle safeCertContext)
 {
     if ((safeCertContext != null) && !safeCertContext.IsInvalid)
     {
         if (((safeCertStoreHandle == null) || safeCertStoreHandle.IsInvalid) || safeCertStoreHandle.IsClosed)
         {
             throw new CryptographicException(SR.GetString("Cryptography_X509_StoreNotOpen"));
         }
         System.Security.Cryptography.SafeCertContextHandle handle = CAPI.CertFindCertificateInStore(safeCertStoreHandle, 0x10001, 0, 0xd0000, safeCertContext.DangerousGetHandle(), System.Security.Cryptography.SafeCertContextHandle.InvalidHandle);
         if ((handle != null) && !handle.IsInvalid)
         {
             GC.SuppressFinalize(handle);
             if (!CAPI.CertDeleteCertificateFromStore(handle))
             {
                 throw new CryptographicException(Marshal.GetLastWin32Error());
             }
         }
     }
 }
 private static unsafe uint GetVersion(System.Security.Cryptography.SafeCertContextHandle safeCertContextHandle)
 {
     CAPIBase.CERT_CONTEXT cert_context = *((CAPIBase.CERT_CONTEXT*) safeCertContextHandle.DangerousGetHandle());
     CAPIBase.CERT_INFO cert_info = (CAPIBase.CERT_INFO) Marshal.PtrToStructure(cert_context.pCertInfo, typeof(CAPIBase.CERT_INFO));
     return (cert_info.dwVersion + 1);
 }
 private static unsafe Oid GetSignatureAlgorithm(System.Security.Cryptography.SafeCertContextHandle safeCertContextHandle)
 {
     CAPIBase.CERT_CONTEXT cert_context = *((CAPIBase.CERT_CONTEXT*) safeCertContextHandle.DangerousGetHandle());
     CAPIBase.CERT_INFO cert_info = (CAPIBase.CERT_INFO) Marshal.PtrToStructure(cert_context.pCertInfo, typeof(CAPIBase.CERT_INFO));
     return new Oid(cert_info.SignatureAlgorithm.pszObjId, System.Security.Cryptography.OidGroup.SignatureAlgorithm, false);
 }
 private static unsafe System.Security.Cryptography.SafeCertStoreHandle SelectFromStore(System.Security.Cryptography.SafeCertStoreHandle safeSourceStoreHandle, string title, string message, X509SelectionFlag selectionFlags, IntPtr hwndParent)
 {
     int num = 0;
     System.Security.Cryptography.SafeCertStoreHandle hCertStore = System.Security.Cryptography.CAPI.CertOpenStore((IntPtr) 2L, 0x10001, IntPtr.Zero, 0, null);
     if ((hCertStore == null) || hCertStore.IsInvalid)
     {
         throw new CryptographicException(Marshal.GetLastWin32Error());
     }
     System.Security.Cryptography.CAPI.CRYPTUI_SELECTCERTIFICATE_STRUCTW csc = new System.Security.Cryptography.CAPI.CRYPTUI_SELECTCERTIFICATE_STRUCTW {
         dwSize = (uint) ((int) Marshal.OffsetOf(typeof(System.Security.Cryptography.CAPI.CRYPTUI_SELECTCERTIFICATE_STRUCTW), "hSelectedCertStore")),
         hwndParent = hwndParent,
         dwFlags = (uint) selectionFlags,
         szTitle = title,
         dwDontUseColumn = 0,
         szDisplayString = message,
         pFilterCallback = IntPtr.Zero,
         pDisplayCallback = IntPtr.Zero,
         pvCallbackData = IntPtr.Zero,
         cDisplayStores = 1
     };
     IntPtr handle = safeSourceStoreHandle.DangerousGetHandle();
     csc.rghDisplayStores = new IntPtr((void*) &handle);
     csc.cStores = 0;
     csc.rghStores = IntPtr.Zero;
     csc.cPropSheetPages = 0;
     csc.rgPropSheetPages = IntPtr.Zero;
     csc.hSelectedCertStore = hCertStore.DangerousGetHandle();
     System.Security.Cryptography.SafeCertContextHandle pCertContext = System.Security.Cryptography.CAPI.CryptUIDlgSelectCertificateW(csc);
     if ((pCertContext != null) && !pCertContext.IsInvalid)
     {
         System.Security.Cryptography.SafeCertContextHandle invalidHandle = System.Security.Cryptography.SafeCertContextHandle.InvalidHandle;
         if (!System.Security.Cryptography.CAPI.CertAddCertificateContextToStore(hCertStore, pCertContext, 7, invalidHandle))
         {
             num = Marshal.GetLastWin32Error();
         }
     }
     if (num != 0)
     {
         throw new CryptographicException(Marshal.GetLastWin32Error());
     }
     return hCertStore;
 }
 private static unsafe int FindTemplateNameCallback(System.Security.Cryptography.SafeCertContextHandle safeCertContextHandle, object pvCallbackData)
 {
     IntPtr zero = IntPtr.Zero;
     IntPtr ptr = IntPtr.Zero;
     CAPIBase.CERT_CONTEXT cert_context = *((CAPIBase.CERT_CONTEXT*) safeCertContextHandle.DangerousGetHandle());
     CAPIBase.CERT_INFO cert_info = (CAPIBase.CERT_INFO) Marshal.PtrToStructure(cert_context.pCertInfo, typeof(CAPIBase.CERT_INFO));
     zero = CAPISafe.CertFindExtension("1.3.6.1.4.1.311.20.2", cert_info.cExtension, cert_info.rgExtension);
     ptr = CAPISafe.CertFindExtension("1.3.6.1.4.1.311.21.7", cert_info.cExtension, cert_info.rgExtension);
     if ((zero != IntPtr.Zero) || (ptr != IntPtr.Zero))
     {
         if (zero != IntPtr.Zero)
         {
             CAPIBase.CERT_EXTENSION cert_extension = (CAPIBase.CERT_EXTENSION) Marshal.PtrToStructure(zero, typeof(CAPIBase.CERT_EXTENSION));
             byte[] destination = new byte[cert_extension.Value.cbData];
             Marshal.Copy(cert_extension.Value.pbData, destination, 0, destination.Length);
             uint cbDecodedValue = 0;
             SafeLocalAllocHandle decodedValue = null;
             if (CAPI.DecodeObject(new IntPtr(0x18L), destination, out decodedValue, out cbDecodedValue))
             {
                 CAPIBase.CERT_NAME_VALUE cert_name_value = (CAPIBase.CERT_NAME_VALUE) Marshal.PtrToStructure(decodedValue.DangerousGetHandle(), typeof(CAPIBase.CERT_NAME_VALUE));
                 if (string.Compare(Marshal.PtrToStringUni(cert_name_value.Value.pbData), (string) pvCallbackData, StringComparison.OrdinalIgnoreCase) == 0)
                 {
                     return 0;
                 }
             }
         }
         if (ptr != IntPtr.Zero)
         {
             CAPIBase.CERT_EXTENSION cert_extension2 = (CAPIBase.CERT_EXTENSION) Marshal.PtrToStructure(ptr, typeof(CAPIBase.CERT_EXTENSION));
             byte[] buffer2 = new byte[cert_extension2.Value.cbData];
             Marshal.Copy(cert_extension2.Value.pbData, buffer2, 0, buffer2.Length);
             uint num2 = 0;
             SafeLocalAllocHandle handle2 = null;
             if (CAPI.DecodeObject(new IntPtr(0x40L), buffer2, out handle2, out num2))
             {
                 CAPIBase.CERT_TEMPLATE_EXT cert_template_ext = (CAPIBase.CERT_TEMPLATE_EXT) Marshal.PtrToStructure(handle2.DangerousGetHandle(), typeof(CAPIBase.CERT_TEMPLATE_EXT));
                 string strB = System.Security.Cryptography.X509Certificates.X509Utils.FindOidInfo(2, (string) pvCallbackData, System.Security.Cryptography.OidGroup.Template);
                 if (strB == null)
                 {
                     strB = (string) pvCallbackData;
                 }
                 if (string.Compare(cert_template_ext.pszObjId, strB, StringComparison.OrdinalIgnoreCase) == 0)
                 {
                     return 0;
                 }
             }
         }
     }
     return 1;
 }
 private static unsafe int FindTimeValidCallback(System.Security.Cryptography.SafeCertContextHandle safeCertContextHandle, object pvCallbackData)
 {
     System.Runtime.InteropServices.ComTypes.FILETIME pTimeToVerify = (System.Runtime.InteropServices.ComTypes.FILETIME) pvCallbackData;
     CAPIBase.CERT_CONTEXT cert_context = *((CAPIBase.CERT_CONTEXT*) safeCertContextHandle.DangerousGetHandle());
     if (CAPISafe.CertVerifyTimeValidity(ref pTimeToVerify, cert_context.pCertInfo) == 0)
     {
         return 0;
     }
     return 1;
 }
 private static unsafe int FindSerialNumberCallback(System.Security.Cryptography.SafeCertContextHandle safeCertContextHandle, object pvCallbackData)
 {
     CAPIBase.CERT_CONTEXT cert_context = *((CAPIBase.CERT_CONTEXT*) safeCertContextHandle.DangerousGetHandle());
     CAPIBase.CERT_INFO cert_info = (CAPIBase.CERT_INFO) Marshal.PtrToStructure(cert_context.pCertInfo, typeof(CAPIBase.CERT_INFO));
     byte[] destination = new byte[cert_info.SerialNumber.cbData];
     Marshal.Copy(cert_info.SerialNumber.pbData, destination, 0, destination.Length);
     int hexArraySize = System.Security.Cryptography.X509Certificates.X509Utils.GetHexArraySize(destination);
     byte[] buffer2 = (byte[]) pvCallbackData;
     if (buffer2.Length != hexArraySize)
     {
         return 1;
     }
     for (int i = 0; i < buffer2.Length; i++)
     {
         if (buffer2[i] != destination[i])
         {
             return 1;
         }
     }
     return 0;
 }
 private static unsafe int FindKeyUsageCallback(System.Security.Cryptography.SafeCertContextHandle safeCertContextHandle, object pvCallbackData)
 {
     CAPIBase.CERT_CONTEXT cert_context = *((CAPIBase.CERT_CONTEXT*) safeCertContextHandle.DangerousGetHandle());
     uint num = 0;
     if (!CAPISafe.CertGetIntendedKeyUsage(0x10001, cert_context.pCertInfo, new IntPtr((void*) &num), 4))
     {
         return 0;
     }
     uint num2 = Convert.ToUInt32(pvCallbackData, null);
     if ((num & num2) == num2)
     {
         return 0;
     }
     return 1;
 }
 private static unsafe int FindExtensionCallback(System.Security.Cryptography.SafeCertContextHandle safeCertContextHandle, object pvCallbackData)
 {
     CAPIBase.CERT_CONTEXT cert_context = *((CAPIBase.CERT_CONTEXT*) safeCertContextHandle.DangerousGetHandle());
     CAPIBase.CERT_INFO cert_info = (CAPIBase.CERT_INFO) Marshal.PtrToStructure(cert_context.pCertInfo, typeof(CAPIBase.CERT_INFO));
     if (CAPISafe.CertFindExtension((string) pvCallbackData, cert_info.cExtension, cert_info.rgExtension) == IntPtr.Zero)
     {
         return 1;
     }
     return 0;
 }
 private static unsafe int FindCertificatePolicyCallback(System.Security.Cryptography.SafeCertContextHandle safeCertContextHandle, object pvCallbackData)
 {
     string strA = (string) pvCallbackData;
     if (strA.Length != 0)
     {
         CAPIBase.CERT_CONTEXT cert_context = *((CAPIBase.CERT_CONTEXT*) safeCertContextHandle.DangerousGetHandle());
         CAPIBase.CERT_INFO cert_info = (CAPIBase.CERT_INFO) Marshal.PtrToStructure(cert_context.pCertInfo, typeof(CAPIBase.CERT_INFO));
         IntPtr ptr = CAPISafe.CertFindExtension("2.5.29.32", cert_info.cExtension, cert_info.rgExtension);
         if (ptr == IntPtr.Zero)
         {
             return 1;
         }
         CAPIBase.CERT_EXTENSION cert_extension = (CAPIBase.CERT_EXTENSION) Marshal.PtrToStructure(ptr, typeof(CAPIBase.CERT_EXTENSION));
         byte[] destination = new byte[cert_extension.Value.cbData];
         Marshal.Copy(cert_extension.Value.pbData, destination, 0, destination.Length);
         uint cbDecodedValue = 0;
         SafeLocalAllocHandle decodedValue = null;
         if (CAPI.DecodeObject(new IntPtr(0x10L), destination, out decodedValue, out cbDecodedValue))
         {
             CAPIBase.CERT_POLICIES_INFO cert_policies_info = (CAPIBase.CERT_POLICIES_INFO) Marshal.PtrToStructure(decodedValue.DangerousGetHandle(), typeof(CAPIBase.CERT_POLICIES_INFO));
             for (int i = 0; i < cert_policies_info.cPolicyInfo; i++)
             {
                 IntPtr ptr2 = new IntPtr(((long) cert_policies_info.rgPolicyInfo) + (i * Marshal.SizeOf(typeof(CAPIBase.CERT_POLICY_INFO))));
                 CAPIBase.CERT_POLICY_INFO cert_policy_info = (CAPIBase.CERT_POLICY_INFO) Marshal.PtrToStructure(ptr2, typeof(CAPIBase.CERT_POLICY_INFO));
                 if (string.Compare(strA, cert_policy_info.pszPolicyIdentifier, StringComparison.OrdinalIgnoreCase) == 0)
                 {
                     return 0;
                 }
             }
         }
     }
     return 1;
 }
 private static unsafe int FindApplicationPolicyCallback(System.Security.Cryptography.SafeCertContextHandle safeCertContextHandle, object pvCallbackData)
 {
     string strA = (string) pvCallbackData;
     if (strA.Length != 0)
     {
         IntPtr ptr = safeCertContextHandle.DangerousGetHandle();
         int num = 0;
         uint num2 = 0;
         SafeLocalAllocHandle invalidHandle = SafeLocalAllocHandle.InvalidHandle;
         if (!CAPISafe.CertGetValidUsages(1, new IntPtr((void*) &ptr), new IntPtr((void*) &num), invalidHandle, new IntPtr((void*) &num2)))
         {
             return 1;
         }
         invalidHandle = CAPI.LocalAlloc(0, new IntPtr((long) num2));
         if (!CAPISafe.CertGetValidUsages(1, new IntPtr((void*) &ptr), new IntPtr((void*) &num), invalidHandle, new IntPtr((void*) &num2)))
         {
             return 1;
         }
         if (num == -1)
         {
             return 0;
         }
         for (int i = 0; i < num; i++)
         {
             string strB = Marshal.PtrToStringAnsi(Marshal.ReadIntPtr(new IntPtr(((long) invalidHandle.DangerousGetHandle()) + (i * Marshal.SizeOf(typeof(IntPtr))))));
             if (string.Compare(strA, strB, StringComparison.OrdinalIgnoreCase) == 0)
             {
                 return 0;
             }
         }
     }
     return 1;
 }