Пример #1
0
        /// <summary>
        /// Helper method add via <see cref="X509Certificate2"/>
        /// </summary>
        /// <param name="store">the store</param>
        /// <param name="certificate">The certificate</param>
        /// <param name="metadata"></param>
        /// <returns></returns>
        public static async Task <CertificateDetails> Add(this ICertificatesStore store, X509Certificate2 certificate, object metadata)
        {
            var privateKey = certificate.PrivateKey as RSA;
            var certBase64 = certificate.ExportToPEM();
            //var publicBase64 = privateKey.ToSubjectPublicKeyInfo();
            var privateBase64 = privateKey.ToRSAPrivateKey();
            var keyId         = certificate.GetSubjectKeyIdentifier();
            var authkeyId     = certificate.GetAuthorityKeyIdentifier();
            var isCA          = certificate.IsCertificateAuthority();
            var response      = await store.Add(new CertificateDetails {
                EncodedCert    = certBase64,
                PrivateKey     = privateBase64,
                KeyId          = keyId.ToLower(),
                SerialNumber   = certificate.SerialNumber?.ToLower(),
                AuthorityKeyId = authkeyId?.ToLower(),
                Algorithm      = "sha256RSA"
            },
                                                certificate.Subject, certificate.Thumbprint, metadata, isCA);

            return(response);
        }