示例#1
0
        private async void SetClientCertificate(ClientCertificate certificate)
        {
            if (certificate == null)
            {
                return;
            }

            try
            {
                var bytes = Convert.FromBase64String(certificate.RawData);
            }
            catch (Exception ex)
            {
                throw new HttpRequestException(FailureMessages.InvalidRawData, ex);
            }

            this.ClientCertificateOptions = ClientCertificateOption.Automatic;

            await CertificateEnrollmentManager.ImportPfxDataAsync(certificate.RawData,
                                                                  certificate.Passphrase,       // the password is blank, but you can specify one here
                                                                  ExportOption.NotExportable,   // there is no reason to keep the certificate Exportable
                                                                  KeyProtectionLevel.NoConsent, // whether any consent is required
                                                                  InstallOptions.DeleteExpired, // no installation options
                                                                  Package.Current.DisplayName);
        }
        private void SetClientCertificate(ClientCertificate certificate)
        {
            if (certificate == null)
            {
                return;
            }

            byte[] bytes;

            try
            {
                bytes = Convert.FromBase64String(certificate.RawData);
            }
            catch (Exception ex)
            {
                throw new HttpRequestException(FailureMessages.InvalidRawData, ex);
            }

            var stream   = new System.IO.MemoryStream(bytes);
            var keyStore = KeyStore.GetInstance("PKCS12");

            keyStore.Load(stream, certificate.Passphrase.ToCharArray());

            var kmf = KeyManagerFactory.GetInstance("X509");

            kmf.Init(keyStore, certificate.Passphrase.ToCharArray());

            KeyManagers = kmf.GetKeyManagers();
        }
        private void SetClientCertificate(ClientCertificate certificate)
        {
            if (certificate == null)
            {
                return;
            }

            byte[] bytes;

            try
            {
                bytes = Convert.FromBase64String(certificate.RawData);
            }
            catch (Exception ex)
            {
                throw new HttpRequestException(FailureMessages.InvalidRawData, ex);
            }

            var options = NSDictionary.FromObjectsAndKeys(new object[] { certificate.Passphrase }, new object[] { "passphrase" });
            var status  = SecImportExport.ImportPkcs12(bytes, options, out NSDictionary[] items);

            var identityRef = items[0]["identity"];
            var identity    = new SecIdentity(identityRef.Handle);

            SecCertificate[] certs = { identity.Certificate };

            this.UrlCredential = new NSUrlCredential(identity, certs, NSUrlCredentialPersistence.ForSession);
        }
示例#4
0
        private async void SetClientCertificate(ClientCertificate certificate)
        {
            if (certificate == null)
            {
                return;
            }

            this.ClientCertificateOptions = ClientCertificateOption.Automatic;

            await CertificateEnrollmentManager.ImportPfxDataAsync(certificate.RawData,
                                                                  certificate.Passphrase,       // the password is blank, but you can specify one here
                                                                  ExportOption.NotExportable,   // there is no reason to keep the certificate Exportable
                                                                  KeyProtectionLevel.NoConsent, // whether any consent is required
                                                                  InstallOptions.DeleteExpired, // no installation options
                                                                  Package.Current.DisplayName);
        }
示例#5
0
        private void SetClientCertificate(ClientCertificate certificate)
        {
            if (certificate == null)
            {
                return;
            }

            var bytes = Convert.FromBase64String(certificate.RawData);

            var stream   = new System.IO.MemoryStream(bytes);
            var keyStore = KeyStore.GetInstance("PKCS12");

            keyStore.Load(stream, certificate.Passphrase.ToCharArray());

            var kmf = KeyManagerFactory.GetInstance("X509");

            kmf.Init(keyStore, certificate.Passphrase.ToCharArray());

            KeyManagers = kmf.GetKeyManagers();
        }