コード例 #1
0
        private void RequestTimeStamp()
        {
            try
            {
                X509Certificate2 sslCert  = null;
                string           password = null;

                if (!string.IsNullOrEmpty(this.UserCertPassword.Text))
                {
                    password = this.UserCertPassword.Text;
                }

                if (!string.IsNullOrEmpty(this.UserCert.Text))
                {
                    sslCert = new X509Certificate2(this.UserCert.Text, password);
                }

                NetworkCredential networkCredential = null;
                if (!string.IsNullOrEmpty(this.UserPassword.Text) || !string.IsNullOrEmpty(this.UserName.Text))
                {
                    networkCredential = new NetworkCredential(this.UserName.Text, this.UserPassword.Text);
                }

                UserCredentials credentials = null;
                if (networkCredential != null || sslCert != null)
                {
                    credentials = new UserCredentials(sslCert, networkCredential);
                }

                TimeStampToken token = SharedUtils.RequestTimeStamp(
                    this.ServerAddress.Text,
                    this.SourceFile.Text,
                    ((ComboItemHash)this.HashAlgorithm.SelectedValue).Value,
                    this.RequestedPolicy.Text,
                    this.Nonce.Text,
                    ((ComboItemCertReq)this.TSACertificate.SelectedValue).Value,
                    credentials,
                    new LogDelegate(this.TextAreaLog),
                    this.LogExceptions.Checked);

                SharedUtils.SaveInFormat(this.SourceFile.Text, token, ((ComboItemFormat)this.ResponseFormat.SelectedValue).Format, this.OutFile.Text);
                this.TextAreaLog(string.Format("Response saved in {0}", this.OutFile.Text));
                MessageBox.Show(string.Format("Time-stamp successfully received."), "Info", MessageBoxType.Information);
            }
            catch (Exception e)
            {
                MessageBox.Show(string.Format("{0}: {1}", e.GetType(), e.Message), "Error", MessageBoxType.Error);
            }
        }