示例#1
0
        /// <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);
        }
示例#2
0
        /// <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);
        }
示例#3
0
 public void SetCertificate(Certificiates certType, byte[] certData)
 {
     SetCertificate(certType.ToString(), certData);
 }
示例#4
0
 public X509Certificate2 GetCertificate(Certificiates certType)
 {
     return(GetByFriendlyName(certType.ToString()));
 }