Signing with DSA Algorithm
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Signing with DSA Algorithm

Hybrid View

  1. #1
    Join Date
    Nov 2013
    Posts
    3

    Exclamation Signing with DSA Algorithm

    Hello everybody
    I am trying to build a small program that can discover whether file/files has been accessed or modified using DSA Signing algorithm.

    I will give you this small example code to describe the issue. suppose that we have a text . We have in our program 2 buttons. When we click the first button we create a digital signature on the text , we also export the parameters and save them. On the second button click we recreate the sign on the same text using the parameters that we exported earlier and compare the new signature with the previous.

    the problem here is that the program (always) gives me a result that the signatures are not the same !!!!

    I used the debugger to know where the problem and found that all variables values are identical between the 2 button_click events, and the difference occures in the signing process. Would you please tell me where the problem is? Here is the code
    Code:
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    using System.Security.Cryptography;
    
    
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            string filename = @"C:\Temporary\Temp.txt";
            DSAParameters parameters;
            byte[] data_to_sign, signature;
    
    
        public Form1()
        {
            InitializeComponent();
        }
    
        
    
        private void Sign_button_Click(object sender, EventArgs e)
        {
    ;
            UnicodeEncoding byteEncoder = new UnicodeEncoding();
            data_to_sign = byteEncoder.GetBytes(filename);
            DSACryptoServiceProvider dsaprovider = new DSACryptoServiceProvider();
            parameters = dsaprovider.ExportParameters(true);
            signature = dsaprovider.SignData(data_to_sign);
            label1.Text = " Signature generated";
        }
    
        private void Verify_button_Click(object sender, EventArgs e)
        {
    
            UnicodeEncoding byteEncoder = new UnicodeEncoding();
            data_to_sign = byteEncoder.GetBytes(filename);
            DSACryptoServiceProvider dsaprovider2 = new DSACryptoServiceProvider();
            dsaprovider2.ImportParameters(parameters);
            byte [] signature2 = dsaprovider2.SignData(data_to_sign);
            if (signature == signature2)
                label1.Text = "The signatres are same";
            else
                label1.Text = "Opp... The signatures are different";
    
        }
    
    }

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,984

    Re: Signing with DSA Algorithm

    signatures are time-based
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Nov 2013
    Posts
    3

    Re: Signing with DSA Algorithm

    Thank you "dglienna" for help
    I finally knew why that happens
    DSA algorithm depends on a random number which is generated first before creating keys.
    This random number - of course- will be different from one DSA object to other and that's cause the difference in signatures.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center