示例#1
0
        /// <summary>
        /// Imports a certificate
        /// </summary>
        /// <param name="certificateName"> the name of the created certificate </param>
        /// <returns> The imported certificate </returns>
        private static CertificateBundle ImportCertificate(out string certificateName)
        {
            var vaultAddress = inputValidator.GetVaultAddress();

            certificateName = inputValidator.GetCertificateName();

            var pfxPath     = inputValidator.GetPfxPath();
            var pfxPassword = inputValidator.GetPfxPassword();

            var policy = new CertificatePolicy
            {
                KeyProperties = new KeyProperties
                {
                    Exportable = true,
                    KeyType    = "RSA"
                },
                SecretProperties = new SecretProperties
                {
                    ContentType = "application/x-pem-file"
                                  //ContentType = CertificateContentType.Pfx
                }
            };

            var base64X509 = string.Empty;

            if (File.Exists(pfxPath))
            {
                var x509Collection = new X509Certificate2Collection();
                x509Collection.Import(pfxPath, pfxPassword, X509KeyStorageFlags.Exportable);

                // A pfx can contain a chain
                var x509Bytes = x509Collection.Cast <X509Certificate2>().Single(s => s.HasPrivateKey).Export(X509ContentType.Pfx, pfxPassword);
                base64X509 = Convert.ToBase64String(x509Bytes);
            }
            else
            {
                //base64X509 = "aaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaa";
                base64X509 = "yourcert";
            }

            var name        = certificateName;
            var certificate = Task.Run(() => keyVaultClient.ImportCertificateAsync(vaultAddress, name, base64X509, pfxPassword,
                                                                                   policy)).ConfigureAwait(false).GetAwaiter().GetResult();

            Console.Out.WriteLine("Created certificate:---------------");
            PrintoutCertificate(certificate);

            return(certificate);
        }
示例#2
0
        /// <summary>
        /// Imports a certificate
        /// </summary>
        /// <param name="certificateName"> the name of the created certificate </param>
        /// <returns> The imported certificate </returns>
        private static CertificateBundle ImportCertificate(out string certificateName)
        {
            var vaultAddress = inputValidator.GetVaultAddress();

            certificateName = inputValidator.GetCertificateName();

            var pfxPath     = inputValidator.GetPfxPath();
            var pfxPassword = inputValidator.GetPfxPassword();

            var policy = new CertificatePolicy
            {
                KeyProperties = new KeyProperties
                {
                    Exportable = true,
                    KeyType    = "RSA"
                },
                SecretProperties = new SecretProperties
                {
                    ContentType = CertificateContentType.Pfx
                }
            };

            var base64X509 = string.Empty;

            if (File.Exists(pfxPath))
            {
                var x509Collection = new X509Certificate2Collection();
                x509Collection.Import(pfxPath, pfxPassword, X509KeyStorageFlags.Exportable);

                // A pfx can contain a chain
                var x509Bytes = x509Collection.Cast <X509Certificate2>().Single(s => s.HasPrivateKey).Export(X509ContentType.Pfx, pfxPassword);
                base64X509 = Convert.ToBase64String(x509Bytes);
            }
            else
            {
                base64X509 = "MIIJOwIBAzCCCPcGCSqGSIb3DQEHAaCCCOgEggjkMIII4DCCBgkGCSqGSIb3DQEHAaCCBfoEggX2MIIF8jCCBe4GCyqGSIb3DQEMCgECoIIE / jCCBPowHAYKKoZIhvcNAQwBAzAOBAj15YH9pOE58AICB9AEggTYLrI + SAru2dBZRQRlJY7XQ3LeLkah2FcRR3dATDshZ2h0IA2oBrkQIdsLyAAWZ32qYR1qkWxLHn9AqXgu27AEbOk35 + pITZaiy63YYBkkpR + pDdngZt19Z0PWrGwHEq5z6BHS2GLyyN8SSOCbdzCz7blj3 + 7IZYoMj4WOPgOm / tQ6U44SFWek46QwN2zeA4i97v7ftNNns27ms52jqfhOvTA9c / wyfZKAY4aKJfYYUmycKjnnRl012ldS2lOkASFt + lu4QCa72IY6ePtRudPCvmzRv2pkLYS6z3cI7omT8nHP3DymNOqLbFqr5O2M1ZYaLC63Q3xt3eVvbcPh3N08D1hHkhz / KDTvkRAQpvrW8ISKmgDdmzN55Pe55xHfSWGB7gPw8sZea57IxFzWHTK2yvTslooWoosmGxanYY2IG / no3EbPOWDKjPZ4ilYJe5JJ2immlxPz + 2e2EOCKpDI + 7fzQcRz3PTd3BK + budZ8aXX8aW / lOgKS8WmxZoKnOJBNWeTNWQFugmktXfdPHAdxMhjUXqeGQd8wTvZ4EzQNNafovwkI7IV / ZYoa++RGofVR3ZbRSiBNF6TDj / qXFt0wN / CQnsGAmQAGNiN + D4mY7i25dtTu / Jc7OxLdhAUFpHyJpyrYWLfvOiS5WYBeEDHkiPUa / 8eZSPA3MXWZR1RiuDvuNqMjct1SSwdXADTtF68l / US1ksU657 + XSC + 6ly1A / upz + X71 + C4Ho6W0751j5ZMT6xKjGh5pee7MVuduxIzXjWIy3YSd0fIT3U0A5NLEvJ9rfkx6JiHjRLx6V1tqsrtT6BsGtmCQR1UCJPLqsKVDvAINx3cPA / CGqr5OX2BGZlAihGmN6n7gv8w4O0k0LPTAe5YefgXN3m9pE867N31GtHVZaJ / UVgDNYS2jused4rw76ZWN41akx2QN0JSeMJqHXqVz6AKfz8ICS / dFnEGyBNpXiMRxrY / QPKi / wONwqsbDxRW7vZRVKs78pBkE0ksaShlZk5GkeayDWC / 7Hi / NqUFtIloK9XB3paLxo1DGu5qqaF34jZdktzkXp0uZqpp + FfKZaiovMjt8F7yHCPk + LYpRsU2Cyc9DVoDA6rIgf + uEP4jppgehsxyT0lJHax2t869R2jYdsXwYUXjgwHIV0voj7bJYPGFlFjXOp6ZW86scsHM5xfsGQoK2Fp838VT34SHE1ZXU / puM7rviREHYW72pfpgGZUILQMohuTPnd8tFtAkbrmjLDo + k9xx7HUvgoFTiNNWuq / cRjr70FKNguMMTIrid + HwfmbRoaxENWdLcOTNeascER2a + 37UQolKD5ksrPJG6RdNA7O2pzp3micDYRs / +s28cCIxO//J/d4nsgHp6RTuCu4+Jm9k0YTw2Xg75b2cWKrxGnDUgyIlvNPaZTB5QbMid4x44/lE0LLi9kcPQhRgrK07OnnrMgZvVGjt1CLGhKUv7KFc3xV1r1rwKkosxnoG99oCoTQtregcX5rIMjHgkc1IdflGJkZzaWMkYVFOJ4Weynz008i4ddkske5vabZs37Lb8iggUYNBYZyGzalruBgnQyK4fz38Fae4nWYjyildVfgyo/fCePR2ovOfphx9OQJi+M9BoFmPrAg+8ARDZ+R+5yzYuEc9ZoVX7nkp7LTGB3DANBgkrBgEEAYI3EQIxADATBgkqhkiG9w0BCRUxBgQEAQAAADBXBgkqhkiG9w0BCRQxSh5IAGEAOAAwA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37YaC8FRSEnnNmS79Dou1Kc3BvK4EYKAD2KxjtUebrV174gD0Q+9YuJ0GXOTspBvCFd5VT2Rw5zDNrA/J3F5fMCk4wOzAfMAcGBSsOAwIaBBSxgh2xyF+88V4vAffBmZXv8Txt4AQU4O/NX4MjxSodbE7ApNAMIvrtREwCAgfQ";
            }

            var name        = certificateName;
            var certificate = Task.Run(() => keyVaultClient.ImportCertificateAsync(vaultAddress, name, base64X509, pfxPassword,
                                                                                   policy)).ConfigureAwait(false).GetAwaiter().GetResult();

            Console.Out.WriteLine("Created certificate:---------------");
            PrintoutCertificate(certificate);

            return(certificate);
        }