static Wincrypt.CTL_ENTRY create_ctlentry(IntPtr handle, String thumbprint) { Wincrypt.CTL_ENTRY entry = new Wincrypt.CTL_ENTRY { SubjectIdentifier = { pbData = get_thumbptr(thumbprint), cbData = (UInt32)(thumbprint.Length / 2) } }; List <UInt32> ids = new List <UInt32>(); Boolean end = false; do { UInt32 retn = Crypt32.CertEnumCertificateContextProperties(handle, 0); if (retn == 0) { end = true; } else { ids.Add(retn); } } while (!end); if (ids.Count > 0) { entry.cAttribute = (UInt32)ids.Count; entry.rgAttribute = create_attributes(handle, ids); } return(entry); }
/// <summary> /// Gets the list of certificate properties associated with the current certificate object. /// </summary> /// <param name="cert">Certificate.</param> /// <exception cref="ArgumentNullException"> /// <strong>cert</strong> parameter is null reference. /// </exception> /// <exception cref="UninitializedObjectException"> /// Certificate object is not initialized and is empty. /// </exception> /// <returns>An array of certificate context property types associated with the current certificate.</returns> public static X509CertificatePropertyType[] GetCertificateContextPropertyList(this X509Certificate2 cert) { if (cert == null) { throw new ArgumentNullException(nameof(cert)); } if (IntPtr.Zero.Equals(cert.Handle)) { throw new UninitializedObjectException(); } List <X509CertificatePropertyType> props = new List <X509CertificatePropertyType>(); UInt32 propID = 0; while ((propID = Crypt32.CertEnumCertificateContextProperties(cert.Handle, propID)) > 0) { props.Add((X509CertificatePropertyType)propID); } return(props.ToArray()); }