Ejemplo n.º 1
0
 private void btnOK_Click(object sender, EventArgs e)
 {
     if (this.CheckInput())
     {
         // 丛文件中读取签名密码是否正确
         this.PrivateKey = SecretUtil.GetPrivateKey(this.txtDigitalSignature.Text, this.txtSignedPassword.Text);
         if (string.IsNullOrEmpty(this.PrivateKey))
         {
             MessageBox.Show(AppMessage.Format(AppMessage.MSG0040, AppMessage.MSGS864), AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
             this.txtSignedPassword.Focus();
             this.txtSignedPassword.SelectAll();
             return;
         }
         if (!string.IsNullOrEmpty(this.DataToSign))
         {
             this.SignedData   = SecretUtil.HashAndSign(this.DataToSign, this.PrivateKey);
             this.DialogResult = DialogResult.OK;
         }
         this.Close();
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 修改签名密码
        /// </summary>
        private bool ChangeSignedPassword()
        {
            bool returnValue = false;

            // 1:这里判断签名文件中的签名密码是否正确?
            string privateKey     = string.Empty;
            string signedPassword = string.Empty;

            try
            {
                signedPassword = SecretUtil.GetSignedPassword(txtDigitalSignature.Text);
                if (!signedPassword.Equals(SecretUtil.md5(this.txtOldPassword.Text, 32)))
                {
                    MessageBox.Show(AppMessage.Format(AppMessage.MSG0040, AppMessage.MSG9961), AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.txtOldPassword.Focus();
                    this.txtOldPassword.SelectAll();
                    return(false);
                }
                // 2:同时可以把私钥读取出来。
                privateKey = SecretUtil.GetPrivateKey(this.txtDigitalSignature.Text, this.txtOldPassword.Text);
            }
            catch
            {
                MessageBox.Show("修改签名密码失败、请重修改签名密码。", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }

            // 3:判断服务器上的签名密码是否正确?
            string statusCode    = string.Empty;
            string statusMessage = string.Empty;

            DotNetService.Instance.LogOnService.ChangeSignedPassword(UserInfo, this.txtOldPassword.Text, this.txtNewPassword.Text, out statusCode, out statusMessage);
            if (statusCode == StatusCode.ChangePasswordOK.ToString())
            {
                // 4:保存签名密钥
                this.SaveDigitalSignature(privateKey, this.txtNewPassword.Text);

                // 修改数字签名后的方法
                if (AfterChangeDigitalSignature != null)
                {
                    AfterChangeDigitalSignature(this.UserInfo.Id);
                }
                else
                {
                    if (BaseSystemInfo.ShowInformation)
                    {
                        // 提示修改成功
                        MessageBox.Show("修改签名密码成功、请妥善保管好签名密钥文件。", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                this.DialogResult = DialogResult.OK;
                returnValue       = true;
            }
            else
            {
                if (statusCode == StatusCode.PasswordCanNotBeNull.ToString())
                {
                    this.ClearOldPassword();
                }
                if (statusCode == StatusCode.OldPasswordError.ToString())
                {
                    this.ClearOldPassword();
                }
                MessageBox.Show(statusMessage, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
                returnValue = false;
            }
            return(returnValue);
        }