public ActionResult <Certificate> Get(string certificateId) { var objectValid = Validator.Validate(certificateId); if (objectValid) { var certificate = Certificates.Find(s => s.Id == certificateId); if (!(certificate is null)) { return(Ok(certificate)); } else { return(NotFound(certificateId)); } }
public X509Certificate FindCertificate() { oStore = new StoreClass(); oStore.Open( CAPICOM_STORE_LOCATION.CAPICOM_CURRENT_USER_STORE, storeName, CAPICOM_STORE_OPEN_MODE.CAPICOM_STORE_OPEN_EXISTING_ONLY | CAPICOM_STORE_OPEN_MODE.CAPICOM_STORE_OPEN_READ_ONLY ); oCerts = (Certificates)oStore.Certificates; oCerts = (Certificates)oCerts.Find(CAPICOM_CERTIFICATE_FIND_TYPE.CAPICOM_CERTIFICATE_FIND_SUBJECT_NAME, "", false); /*oCerts = (Certificates)oCerts.Find( * CAPICOM_CERTIFICATE_FIND_TYPE.CAPICOM_CERTIFICATE_FIND_SUBJECT_NAME, filter, false);*/ // foreach(Certificate ocert in oCerts) //Certificates is IEnumerable // { // ocert.Display(); // } //--- get first cert using indexer, retrieve ICertContext and use from managed code ----- if (oCerts.Count > 0) { Certificate firstcert = (Certificate)oCerts[1]; //firstcert.Display() ; ICertContext iCertCntxt = (ICertContext)firstcert; int certcntxt = iCertCntxt.CertContext; IntPtr hCertCntxt = new IntPtr(certcntxt); if (hCertCntxt != IntPtr.Zero) { //use certcontext from managed code string s = ""; s += " CertContext: " + hCertCntxt.ToInt32(); X509Certificate foundcert = new X509Certificate(hCertCntxt); s += " subject name: " + foundcert.GetName(); s += " serial no: " + foundcert.GetSerialNumberString(); s += " hash string:" + foundcert.GetCertHashString(); return(foundcert); } } return(null); }
/// <summary> /// Loads the Client Certificate from the Certificate Store /// </summary> /// <param name="certStore"></param> /// <param name="isMachineStore"></param> /// <param name="subjectsName"></param> public void LoadCliCertFromCerStore(string certStore, bool isMachineStore, string subjectsName) { try { // Store store = new Store(); // // store.Open(isMachineStore ? CAPICOM_STORE_LOCATION.CAPICOM_LOCAL_MACHINE_STORE : CAPICOM_STORE_LOCATION.CAPICOM_CURRENT_USER_STORE, // certStore, CAPICOM_STORE_OPEN_MODE.CAPICOM_STORE_OPEN_READ_ONLY); // // int nr = 0; // foreach (Certificate cert in store.Certificates) // { // nr++; // if (cert.SubjectName.IndexOf(subjectsName) > 0) // { // ClientCert = cert; // store.Close(); // return; // } // } // store.Close(); StoreClass oStore = new StoreClass(); oStore.Open( CAPICOM_STORE_LOCATION.CAPICOM_CURRENT_USER_STORE, certStore, CAPICOM_STORE_OPEN_MODE.CAPICOM_STORE_OPEN_EXISTING_ONLY | CAPICOM_STORE_OPEN_MODE.CAPICOM_STORE_OPEN_READ_ONLY ); Certificates oCerts = (Certificates)oStore.Certificates; oCerts = (Certificates)oCerts.Find(CAPICOM_CERTIFICATE_FIND_TYPE.CAPICOM_CERTIFICATE_FIND_SUBJECT_NAME, "", false); if (oCerts.Count > 0) { ClientCert = (Certificate)oCerts[1]; } } catch (COMException e) { throw e; } }