/// <summary> /// Gets certificate from store by its type corresponding to friendly name. /// </summary> /// <param name="certType">Certificate type</param> /// <returns>Found certificate</returns> public X509Certificate2 GetCertificate(Certificiates certType) { var certs = _store.Certificates.Cast <X509Certificate2>(); var cert = certs.FirstOrDefault(x => x.FriendlyName == certType.ToString()); return(cert); }
/// <summary> /// Saves certificate in store by its type corresponding to friendly name. /// </summary> /// <param name="certType">Certificate type</param> /// <param name="certData">Raw data of the certificate</param> public void SetCertificate(Certificiates certType, byte[] certData) { var oldCert = GetCertificate(certType); if (oldCert != null) { _store.Remove(oldCert); } var newCert = new X509Certificate2(certData, "", X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet); // Mark the (potentially) private key as exportable newCert.FriendlyName = certType.ToString(); _store.Add(newCert); }
public void SetCertificate(Certificiates certType, byte[] certData) { SetCertificate(certType.ToString(), certData); }
public X509Certificate2 GetCertificate(Certificiates certType) { return(GetByFriendlyName(certType.ToString())); }