internal static bool CertDeleteCertificateFromStore([In] System.Security.Cryptography.SafeCertContextHandle pCertContext)
 {
     if (pCertContext == null)
     {
         throw new ArgumentNullException("pCertContext");
     }
     if (pCertContext.IsInvalid)
     {
         throw new CryptographicException(SR.GetString("Cryptography_InvalidHandle"), "pCertContext");
     }
     new StorePermission(StorePermissionFlags.RemoveFromStore).Demand();
     return(CAPIUnsafe.CertDeleteCertificateFromStore(pCertContext));
 }
 internal static bool CertSetCertificateContextProperty([In] System.Security.Cryptography.SafeCertContextHandle pCertContext, [In] uint dwPropId, [In] uint dwFlags, [In] IntPtr pvData)
 {
     if (pvData == IntPtr.Zero)
     {
         throw new ArgumentNullException("pvData");
     }
     if (((dwPropId != 0x13) && (dwPropId != 11)) && ((dwPropId != 0x65) && (dwPropId != 2)))
     {
         throw new ArgumentException(SR.GetString("Security_InvalidValue"), "dwFlags");
     }
     if (((dwPropId == 0x13) || (dwPropId == 11)) || (dwPropId == 2))
     {
         new PermissionSet(PermissionState.Unrestricted).Demand();
     }
     return(CAPIUnsafe.CertSetCertificateContextProperty(pCertContext, dwPropId, dwFlags, pvData));
 }
 internal static bool CertSetCertificateContextProperty([In] System.Security.Cryptography.SafeCertContextHandle pCertContext, [In] uint dwPropId, [In] uint dwFlags, [In] SafeLocalAllocHandle safeLocalAllocHandle)
 {
     if (pCertContext == null)
     {
         throw new ArgumentNullException("pCertContext");
     }
     if (pCertContext.IsInvalid)
     {
         throw new CryptographicException(SR.GetString("Cryptography_InvalidHandle"), "pCertContext");
     }
     if (((dwPropId != 0x13) && (dwPropId != 11)) && ((dwPropId != 0x65) && (dwPropId != 2)))
     {
         throw new ArgumentException(SR.GetString("Security_InvalidValue"), "dwFlags");
     }
     if (((dwPropId == 0x13) || (dwPropId == 11)) || (dwPropId == 2))
     {
         new PermissionSet(PermissionState.Unrestricted).Demand();
     }
     return(CAPIUnsafe.CertSetCertificateContextProperty(pCertContext, dwPropId, dwFlags, safeLocalAllocHandle));
 }
 internal static System.Security.Cryptography.SafeCertContextHandle CertEnumCertificatesInStore([In] System.Security.Cryptography.SafeCertStoreHandle hCertStore, [In] System.Security.Cryptography.SafeCertContextHandle pPrevCertContext)
 {
     if (hCertStore == null)
     {
         throw new ArgumentNullException("hCertStore");
     }
     if (hCertStore.IsInvalid)
     {
         throw new CryptographicException(SR.GetString("Cryptography_InvalidHandle"), "hCertStore");
     }
     if (pPrevCertContext.IsInvalid)
     {
         new StorePermission(StorePermissionFlags.EnumerateCertificates).Demand();
     }
     System.Security.Cryptography.SafeCertContextHandle handle = CAPIUnsafe.CertEnumCertificatesInStore(hCertStore, pPrevCertContext);
     if (((handle == null) || handle.IsInvalid) && (Marshal.GetLastWin32Error() != -2146885628))
     {
         throw new CryptographicException(Marshal.GetLastWin32Error());
     }
     return(handle);
 }
        internal static unsafe string GetCertNameInfo([In] System.Security.Cryptography.SafeCertContextHandle safeCertContext, [In] uint dwFlags, [In] uint dwDisplayType)
        {
            if (safeCertContext == null)
            {
                throw new ArgumentNullException("pCertContext");
            }
            if (safeCertContext.IsInvalid)
            {
                throw new CryptographicException(SR.GetString("Cryptography_InvalidHandle"), "safeCertContext");
            }
            uint num = 0x2000003;
            SafeLocalAllocHandle invalidHandle = SafeLocalAllocHandle.InvalidHandle;

            if (dwDisplayType == 3)
            {
                invalidHandle = System.Security.Cryptography.X509Certificates.X509Utils.StringToAnsiPtr("2.5.4.3");
            }
            uint cchNameString = 0;
            SafeLocalAllocHandle pszNameString = SafeLocalAllocHandle.InvalidHandle;

            cchNameString = CAPISafe.CertGetNameStringW(safeCertContext, dwDisplayType, dwFlags, (dwDisplayType == 3) ? invalidHandle.DangerousGetHandle() : new IntPtr((void *)&num), pszNameString, 0);
            if (cchNameString == 0)
            {
                throw new CryptographicException(Marshal.GetLastWin32Error());
            }
            pszNameString = LocalAlloc(0, new IntPtr((long)(2 * cchNameString)));
            if (CAPISafe.CertGetNameStringW(safeCertContext, dwDisplayType, dwFlags, (dwDisplayType == 3) ? invalidHandle.DangerousGetHandle() : new IntPtr((void *)&num), pszNameString, cchNameString) == 0)
            {
                throw new CryptographicException(Marshal.GetLastWin32Error());
            }
            string str = Marshal.PtrToStringUni(pszNameString.DangerousGetHandle());

            pszNameString.Dispose();
            invalidHandle.Dispose();
            return(str);
        }
 internal static System.Security.Cryptography.SafeCertContextHandle CertDuplicateCertificateContext([In] System.Security.Cryptography.SafeCertContextHandle pCertContext)
 {
     if ((pCertContext != null) && !pCertContext.IsInvalid)
     {
         return(CAPISafe.CertDuplicateCertificateContext(pCertContext));
     }
     return(System.Security.Cryptography.SafeCertContextHandle.InvalidHandle);
 }
 internal static bool CertAddCertificateLinkToStore([In] System.Security.Cryptography.SafeCertStoreHandle hCertStore, [In] System.Security.Cryptography.SafeCertContextHandle pCertContext, [In] uint dwAddDisposition, [In, Out] System.Security.Cryptography.SafeCertContextHandle ppStoreContext)
 {
     if (hCertStore == null)
     {
         throw new ArgumentNullException("hCertStore");
     }
     if (hCertStore.IsInvalid)
     {
         throw new CryptographicException(SR.GetString("Cryptography_InvalidHandle"), "hCertStore");
     }
     if (pCertContext == null)
     {
         throw new ArgumentNullException("pCertContext");
     }
     if (pCertContext.IsInvalid)
     {
         throw new CryptographicException(SR.GetString("Cryptography_InvalidHandle"), "pCertContext");
     }
     new StorePermission(StorePermissionFlags.AddToStore).Demand();
     return(CAPIUnsafe.CertAddCertificateLinkToStore(hCertStore, pCertContext, dwAddDisposition, ppStoreContext));
 }
 internal static System.Security.Cryptography.SafeCertContextHandle CertFindCertificateInStore([In] System.Security.Cryptography.SafeCertStoreHandle hCertStore, [In] uint dwCertEncodingType, [In] uint dwFindFlags, [In] uint dwFindType, [In] IntPtr pvFindPara, [In] System.Security.Cryptography.SafeCertContextHandle pPrevCertContext)
 {
     if (hCertStore == null)
     {
         throw new ArgumentNullException("hCertStore");
     }
     if (hCertStore.IsInvalid)
     {
         throw new CryptographicException(SR.GetString("Cryptography_InvalidHandle"), "hCertStore");
     }
     return(CAPIUnsafe.CertFindCertificateInStore(hCertStore, dwCertEncodingType, dwFindFlags, dwFindType, pvFindPara, pPrevCertContext));
 }