예제 #1
0
파일: MainForm.cs 프로젝트: zhao0876/mtapi
        private void buttonSign_Click(object sender, EventArgs e)
        {
            string privateKey = textBoxPrivateKey.Text;

            if (string.IsNullOrEmpty(privateKey) == false)
            {
                string accountName   = textBoxAccountName.Text;
                string accountNumber = textBoxAccountNumber.Text;

                if (string.IsNullOrEmpty(accountName) == false)
                {
                    if (string.IsNullOrEmpty(accountNumber) == false)
                    {
                        string inputData = accountName + accountNumber;

                        textBoxSignature.Text = DigitalSignatureHelper.CreateSignature(inputData, privateKey);
                    }
                    else
                    {
                        MessageBox.Show("AccountNumber is empty!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                else
                {
                    MessageBox.Show("AccountName is empty!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else
            {
                MessageBox.Show("Private Key is empty!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
예제 #2
0
파일: MainForm.cs 프로젝트: zhao0876/mtapi
        private void buttonGetPublicKey_Click(object sender, EventArgs e)
        {
            string privateKey = textBoxPrivateKey.Text;

            if (string.IsNullOrEmpty(privateKey) == false)
            {
                textBoxPublicKey.Text = DigitalSignatureHelper.GetPublicKey(privateKey);
            }
            else
            {
                MessageBox.Show("Private Key is empty!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
예제 #3
0
파일: MainForm.cs 프로젝트: zhao0876/mtapi
        private void buttonGenerateKey_Click(object sender, EventArgs e)
        {
            textBoxPrivateKey.Text = DigitalSignatureHelper.GeneratePrivateKey();

            mIsSaved = false;
        }
예제 #4
0
파일: MainForm.cs 프로젝트: zhao0876/mtapi
        private void buttonVerify_Click(object sender, EventArgs e)
        {
            string publicKey = textBoxPublicKey.Text;

            if (string.IsNullOrEmpty(publicKey) == false)
            {
                string signature = textBoxSignature.Text;

                if (string.IsNullOrEmpty(signature) == false)
                {
                    string accountName   = textBoxAccountName.Text;
                    string accountNumber = textBoxAccountNumber.Text;

                    if (string.IsNullOrEmpty(accountName) == false)
                    {
                        if (string.IsNullOrEmpty(accountNumber) == false)
                        {
                            string inputData    = accountName + accountNumber;
                            var    verifyResult = false;
                            try
                            {
                                verifyResult = DigitalSignatureHelper.VerifySignature(inputData, signature, publicKey);
                            }
                            catch (SecurityException ex)
                            {
                                MessageBox.Show(ex.Message, "Verify", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                verifyResult = false;
                            }
                            catch (Exception ex)
                            {
                                string errorMsg = string.Format("Verify process failed!\n{0}", ex.Message);
                                MessageBox.Show(errorMsg, "Verify", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                verifyResult = false;
                            }

                            if (verifyResult == true)
                            {
                                MessageBox.Show("Signature good", "Verify", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                        }
                        else
                        {
                            MessageBox.Show("AccountNumber is empty!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    else
                    {
                        MessageBox.Show("AccountName is empty!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }

                else
                {
                    MessageBox.Show("Signature is empty!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else
            {
                MessageBox.Show("Public Key is empty!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }