473,385 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Digital Signature Verification in .NET

We have two files, one is plain text another is signature file. We have to verify the integrity of the message.

The details of SIG file is as under:
Digital signature in PKCS7 format
Signatures are attached in detach mode
Algorithm : SHA1
Signature rule: End certificate of the User. .

What we are doing is
1. Calculating the hash of plain text file say it is hasPlain
2. Extracting the public key from SIG file
3. Extracting the Encrypted Hash from SIG file
4. Decrypting the above hash by using public key say it will give us hashSign
5. Comparing hashPlain and hasSign, if both are equal then signature is verified
6. We are using RSACryptoserviceprovider class of .net

We are able to extract the public key from SIG file but we are not able to extract Encrypted Hash from SIG File.

Please help
Jul 31 '08 #1
3 3587
Curtis Rutland
3,256 Expert 2GB
So what have you tried so far?
Jul 31 '08 #2
Expand|Select|Wrap|Line Numbers
  1. X509Certificate2 x509_2 = new X509Certificate2("c:\\EP00000100008052201.sig")
  2. byte[] cer_data = x509_2.PublicKey.Key
  3.  
  4. FileStream fsw = new FileStream("C:\\cc.cer", FileMode.OpenOrCreate, FileAccess.Write);
  5.             fsw.Write(cer_data, 0, cer_data.Length);
  6.             fsw.Close();
  7. // certificate has been generated 
  8.  
  9.             FileStream fs1 = new FileStream("c:\\EP00000100008052201.sig", FileMode.Open, FileAccess.Read);
  10.             byte[] tot_bytes = new byte[fs1.Length];
  11.             fs1.Read(tot_bytes, 0, tot_bytes.Length);
  12.             fs1.Close();
  13.             fsw = new FileStream("C:\\left.sig", FileMode.OpenOrCreate,FileAccess.Write);
  14.  
  15.             string shouldIWrite;
  16.             int tot = 0;
  17.             for (int i = 0; i < tot_bytes.Length; i++)
  18.             {
  19.                 shouldIWrite = "Y";
  20.                 for (int j = 0; j < cer_data.Length; j++)
  21.                 {
  22.                     if (tot_bytes[i] == cer_data[j])
  23.                         shouldIWrite = "N";
  24.                 }
  25.                 if (shouldIWrite == "Y")
  26.                 {
  27.                     tot++;
  28.                     fsw.WriteByte(tot_bytes[i]);
  29.                 }
  30.             }
  31.             fsw.Close();
  32.  
  33.  
  34.             FileStream fs = new FileStream("c:\\EP00000100008052201.txt", FileMode.Open, FileAccess.Read);
  35.             byte[] plainbyte = new byte[fs.Length];
  36.             fs.Read(plainbyte, 0, plainbyte.Length);
  37.             SHA1 sha = new SHA1CryptoServiceProvider();
  38.             byte[] plain_hash = sha.ComputeHash(plainbyte);
  39.             fs.Close();
  40.  
  41.             fs = new FileStream("C:\\left.sig", FileMode.Open, FileAccess.Read);
  42.             byte[] leftout_bytes = new byte[fs.Length];
  43.             fs.Read(leftout_bytes, 0, leftout_bytes.Length);
  44.             fs.Close();
  45.  
  46.             RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
  47.             rsa.FromXmlString(x509_2.PublicKey.Key.ToXmlString(false));
  48.  
  49.             byte[] encrypted_data = rsa.Decrypt(leftout_bytes,true);
  50.  
  51. // here we are facing the problem
  52. // once we will decrypt it we can get the hash and then compare with the hash of plain file calculated earlier
  53.  
  54.  
  55.             if (plainbyte == encrypted_data)
  56.                 MessageBox.Show("Y");
  57.             else
  58.                 MessageBox.Show("N");
  59.  
Aug 5 '08 #3
Frinavale
9,735 Expert Mod 8TB
Have you manually checked that the decryption is working properly?
Are you sure that you are reading leftout_bytes contains all of the bytes required for the decryption to work correctly?

-Frinny
Aug 5 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Kim H Madsen | last post by:
I have created a .Net Service that is sending mails using SMTP Server/Exchange Server how do i put in a Digital Signature so the reciver is 100% sure that the mail i from the owner of Server where...
0
by: CLarkou | last post by:
I bought a digital signature for my MSaccess application in Office 2003. I select TOOLS\Digital Signatures in Visual Basic Editor and I am not able to see my digital signature in the available...
3
by: Xavier | last post by:
hello, i have a kind of workflow like: enter data in a form aprove data by person 1 aprove data by person 2 data are saved in a sqldatabase
0
by: Geagleeye | last post by:
Hi everyone. I have some vba code to generate a pdf document through word, and add also digital signature. My problem is : how can i change the way the signature layout, it always show the...
2
by: Ralph.Malek | last post by:
Would anyone happen to know how to determine if a digital signature used MD5 or SHA1 as the digest algorithm? I have a requirement to verify the authenticity of VeriSigned exe file, and while...
2
by: sudankanakavel | last post by:
i need a software which implement digital signature using algorithm:rsa,elgamal language:java os:windows software should compress,encrypt and sign data. decryption,certificate...
0
by: =?Utf-8?B?S29saW4=?= | last post by:
Hi There, I am a newbe to web services and WSE 3.0. I am connecting to a remote web service using Web Proxy and the remote service required the soap message to be digitaly signed(X509...
3
by: itcoll | last post by:
i have wriiten java code for client server communication - the client sends a digital signature and the server verifies it using the public key .I have sent the signature as a string from the client...
3
by: tmoloy | last post by:
I am using RFID tags to store some data which will then be read by a 3rd party. I need to include a digital signature (or some variation) along with the data so that the 3rd party can verify the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.