Exemplo n.º 1
0
        private void browseDSBtn_Click(object sender, EventArgs e)
        {
            digitalSignPathLabel.Text = string.Empty;
            dsInput.Text  = string.Empty;
            SignaturePath = string.Empty;

            using OpenFileDialog openFileDialog = new OpenFileDialog
                  {
                      Filter           = "txt files (*.txt)|*.txt|All files (*.*)|*.*",
                      FilterIndex      = 2,
                      RestoreDirectory = true
                  };

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                SignaturePath             = openFileDialog.FileName;
                digitalSignPathLabel.Text = FilePath;

                try
                {
                    var signatureContent = File.ReadAllText(SignaturePath);
                    var signTuple        = DsaSerializer.Deserialize(signatureContent);

                    dsInput.Text = signTuple.ToString();
                } catch (Exception ex)
                {
                    MessageBox.Show("Error: Signature file is corrupt.");
                    return;
                }
            }
        }
Exemplo n.º 2
0
        private void verifyBtn_Click(object sender, EventArgs e)
        {
            dsInput.Text = string.Empty;
            if (string.IsNullOrWhiteSpace(FilePath))
            {
                MessageBox.Show("Error: Choose a file.");
                return;
            }
            if (string.IsNullOrWhiteSpace(SignaturePath))
            {
                MessageBox.Show("Error: Choose a file with signature.");
                return;
            }

            try
            {
                var signatureContent = File.ReadAllText(SignaturePath);
                var signTuple        = DsaSerializer.Deserialize(signatureContent);

                dsInput.Text = signTuple.ToString();

                var verifyResult = dsa.Verify(MessageBytes, signTuple.Item1, signTuple.Item2);
                if (verifyResult)
                {
                    MessageBox.Show("File is valid!");
                }
                else
                {
                    MessageBox.Show("File is invalid!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: Signature file is corrupt.");
                return;
            }
        }
Exemplo n.º 3
0
        private void signBtn_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(FilePath))
            {
                MessageBox.Show("Error: Choose a file.");
                return;
            }

            try
            {
                var signTuple = dsa.SignData(MessageBytes);

                // save signature to file
                File.WriteAllText(FilePath.Substring(0, FilePath.IndexOf('.')) + "_Sign.txt", DsaSerializer.Serialize(signTuple));

                MessageBox.Show("File was signed successfully.");
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Error: {ex.Message}");
            }
        }