473,698 Members | 2,156 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

headache with applying and verifying of digital signature - C#

Hi
i'm trying to sign a file and verify its signature with a DSA key. But
i don't know if i'm doing it the right way !. I tried 2 different ways
but i either got an error or simply the verification just failed.
Here's what i did

in the 1st attempt i generated the hash for the file and then tried to
sign that hash by chunks of 20 bytes ( otherwise i would get an
Exception "SHA1 algorithm key size is 20 bytes") and at the end i
would concatenate the signed chunks and write them to the end of the
file. I also verified that every 20 bytes, when signed, generate 40
bytes, i don't know if this is a standard.
Anyway for verification,as suming that the signature from phase 1 is
written to the end of the file, i followed the same tactic used to
generate it, meaning verifying signature by chunks: i would read off
40 bytes from the signature at the end of the file, and then 20 bytes
from the computed hash and sign it and then compare, but this always
fails !

to sign
senderPk is a DSACryptoServic eProvider Object
1 List<bytesign = new List<byte>();
2 int offset = 0;
3 String oid = CryptoConfig.Ma pNameToOID("SHA 1");
4 while (offset < computedHash.Le ngth)
5 {
6 byte[] chunk = new byte[20];
7 int copySize = (computedHash.L ength -
offset) 20 ? 20 : computedHash.Le ngth - offset;
8 Array.Copy(comp utedHash,offset , chunk, 0,
copySize);
9 offset += 20;
10
11 byte[] signedHash =
senderPk.SignHa sh(chunk,oid);
12 sign.AddRange(s ignedHash);
13 }
14
15 senderPk.Clear( );
16 //cout.Write(comp utedHash, 0,
computedHash.Le ngth);
17 // flush all the data encrypted with the
symmetric key
18 cout.FlushFinal Block();
19 cout.Flush();
to verify
dsa is a DSACryptoServic eProvider Object

1 // dsa is the sender public key
2 // fin is the FileStream opened on the file
3 //computed hash is the hash computed while
decrypting the file
4 List<byteleft = new List<byte>();
5 int leftByte;
6 while ((leftByte = fin.ReadByte()) != -1)
7 left.Add((byte) leftByte);
8 List<bytesign = new List<byte>();
9 int offset = 0,sOffset=0;
10 byte[] computedHash =
hasher.Hash,sig nedHash = left.ToArray();
11 bool goodSignature = true;
12 String oid =
CryptoConfig.Ma pNameToOID("SHA 1");
13 byte[] chunk = new byte[20], sChunk = new
byte[40];
14 while (offset < computedHash.Le ngth &&
goodSignature)
15 {
16 int copySize = (computedHash.L ength -
offset) 20 ? 20 : computedHash.Le ngth - offset;
17 Array.Copy(comp utedHash, offset, chunk,
0, copySize);
18 copySize = (signedHash.Len gth -
sOffset) 40 ? 40 : signedHash.Leng th - sOffset;
19 Array.Copy(sign edHash, sOffset, sChunk,
0, copySize);
20 offset += 20;sOffset+=40;
21 goodSignature =
dsa.VerifyHash( chunk,oid, sChunk);
22 sign.AddRange(s ignedHash);
23 }
24 if (!goodSignature )
25 {
26 Console.WriteLi ne("file verification
failed ! signatures do not macth");
27 return false;
28
29 }

this way, the verification process will always fail.
and if i use the one pass method meaning i try to sign or verify the
file in just one pass i get the following exception
System.Security .Cryptography.. CryptographicEx ception "SHA1 algorithm
key size is 20 bytes"

the DSA key is a DSACryptoServic eProvider instance in all cases.
Language is C# and .NET version is 3.0

already tried posting at the .NET forums on msdn but got no answer so
If someone could provide me with a sample code on how to sign and
verify the signature, it'd be great !
Jun 27 '08 #1
0 1446

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1161
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 the Service is running ? It should worke something lige Outlook does it you type in your secret password and Outlook together with the code create a Mail with digital signature Thank Ki If I have to use another way of sending mails to use...
7
7651
by: Guangxi Wu | last post by:
Hi all, Happy New Year. I am using SignedXML and an X509 certificate to digitally sign a SOAP message body and put the signature in the SOAP header for a B2B business application. Can you suggest which type of digital certificates from VeriSign is for this purpose? I checked VeriSign's web site but didn't find it obvious to decide.
5
4826
by: John Campbell | last post by:
Hi everyone I've been doing my best to understand the specifics of implimentating XML Digital Signatures, but I seem to be missing a fundamental concept. Let me start with a description of the problem I am trying to solve. In my application, people send an XML file that contains data for loans. The application then takes that data and performs various calculations returning the results in an XML file that combines both the initial data and...
1
6234
by: claudia_usa | last post by:
Hello, Does anyone know how to include the signature field when creating PDF crystal reports with VB.net? Our intension is to allow the user to generate the report with their digital signature included or at least with the signature field available within Adobe Reader so that it can be signed independently with Reader. Is there an SDK, plug-in or license that we need?
5
4594
by: Mitchell Vincent | last post by:
I've recently started signing all EXEs that come out of here. I would like to verify the signature at startup to detect any changes to the EXE itself. Is something like that possible? I'm using VB.NET 2003.. -- - Mitchell Vincent
0
1978
by: amolom | last post by:
Hi members I am new to xml digital signature methodology. I want to know how we can verify the xml digital signature with the public key certificate. Does .Net provide any inbuild class to verifiy the xml response. Regards Amol Lokhande
1
1618
by: Saurabh Agrawal | last post by:
Hi Friends, I have to store some documents (word, pdf, images and text) files in sql server database. I want to apply digital signature to these documents before storing documents in sql server. When user will see thses documents , they may also request to varify that the document is not tampered after digital signing. Can anyone please tell me how to achieve this in asp.net website. Also suggest some tools if It can not be done by doing just...
2
1388
by: plemon | last post by:
this script was working now ive added to it and its no longer my friend. here is the very first one <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;
3
3172
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 authenticity of the tag. Straightforward enough. But the problem is that I am constrained by the RFID tag's 32-byte memory array. My application is written in C# (.NET 3.5) and the available digital signature class (DSACryptoServiceProvider) results...
0
8674
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9157
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9027
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8895
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7725
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.