Click here to monitor SSC
Av rating:
Total votes: 56
Total comments: 25


Matteo Slaviero
Beginning with Digital Signatures in .NET Framework
07 October 2009

Digital Signatures aren't the most intuitive software devices to explain, but Matteo boldly gives a quick-start account of Asymmetric Cryptography and Digital Signatures before demonstrating how simple it can be to perform a signature using an X509 certificate and .NET Framework base classes

This article explains how to get started with digital signatures, using X509 certificates in .NET. 

The purpose of digital signatures is to identify data in a way that cannot easily be faked.  Phishing, infected software and illegal contents published by unknown subjects can be prevented with digital signatures. Digital signatures will allow data and digital documents to be used as if they were signed paper. Browsers are now able to recognize X.509 certificates and know which Certificate Authorities are trusted. The X.509 system has grown to be the standard format for public key certificates, and is therefore the best way of proving that a document comes from the source it claims to come from.

This article will introduce X509 certificates, explain a little about the asymmetric cryptography that is at their heart, and end by describing how to use and manage these certificates within the .NET Framework classes.

Asymmetric Cryptography and Digital Signatures

Digital signatures are created using asymmetric cryptography, the approach on which digital signatures are based. Asymmetric Cryptography is distinguished by having two different keys, a private key to encrypt messages and a public key to decrypt them. The cryptographic private key K0 (a suitable array of bytes) is used with an appropriate algorithm to  transform the initial human-readable message into a different message that is encrypted.

A second public cryptographic key K1, which is related to the private one, is used to change the encrypted message back to its original decrypted form via a second related algorithm.

With this mechanism, your recipient is sure that the message that she/he received is your message, because only you hold the private key that is related to the public, shared, key. You digitally ‘sign’ your message.

In practice, you will hash the message beforehand (with hash algorithm such as MD5 or SHA1), obtaining the hashed message M1. Then you will encrypt M1 with your private key K0, digitally signing your message, and, finally, you will send your message M, the encrypted hash M1 (the signature) and the public key K1 to your recipient. Your recipient will compute the hash of your message M and will compare it with the decrypted value of M1. If the two hashes matches, the signature is valid.

 You will notice that the signature is obtained by encrypting the hash of a message, rather than  the message itself. This is done for performance reasons.  Asymmetric cryptography is a slow process and the time required to encrypt, or decrypt, a message is directly related to the message length.  You can make better use of the processor by reducing the amount of data to be processed. Sometimes, a very large (in bytes) message, can be reduced, by hashing it, to a much smaller hashed message. It is more convenient to transmit a the bulk of the data as clear text and just attach less than a hundred encrypted bytes attached to it than to encrypt the entire message and send it in the encrypted form.

Asymmetric key encryption by itself is not enough because it is necessary to trust the public key received. An attacker can deceive you by signing a message with his private key and send you a digitally confirmed message with its (related) public key, whilst  pretending he is someone  else.

The public-key infrastructure (PKI) avoids this by utilizing a third-party entity, called Certification Authority that, under its responsibility, binds a public key to its owner. The binding occurs when the Certification Authority digitally sign a message that contains the public key and the identity of its owner. A digital certificate is obtained.

The X509 Standard for Digital Certificate

Today, the standard  that has been adopted for digital certificate format is the X509 standard. Over the years since X.509 was developed in 1988, the initial X509 certificate format has evolved beyond the simple purpose of associating the identity of the subject with the public key, since it allows extended information to be held. The current certificate format is X509 v3 format, defined on RFC 5280. The most important information fields  that it holds  and stores is

  • Issuer: The identity of the certification authority that signed the certificate, validating it. It is expressed in ITU-T X.501 Distinguished Name format.
  • Validity: it defines the dates between which the certificate can be used.
  • Subject: it defines the identity of the public key owner. It is expressed as ITU-T X.501 Distinguished Name format.
  • SubjectPublicKeyInfo: it contains an encoded version of the public key.
  • X509 v3 extensions:  it defines a set of extensions that establishes the purpose of the certificate and set some properties related to its management. Each extension can be critical (e.g. cannot be ignored) or not.

    Among the X509 v3 extensions,  the two most important are

    • Key Usage: it defines the usage allowed for the private key, for example digitalSignature (allow the digital signature), keyCertSign (allow the signature of certificates by a certification authority), keyAgreement (allow the key exchange on protocol such as TLS/SSL).
    • Extended Key Usage:  it defines extended properties in relation to the usage of the private key. For example Server Authentication (for TLS/SSL certificate), Code Signing (for authenticode signature), Email Protection (for protocol such as S/MIME).

You can view the certificates installed on a Windows® machine by using  certmgr.msc

 

In the details tab, you can see the binding between the subject identity (Subject field) and the Public Key (Public Key field). This is highlighted to show its content. It consists of a sequence of bytes in hexadecimal form.

An important feature of the X509 standard is the assignment of a unique identifier to each entity inside a X509 certificate which is in the form of a sequence of numbers organized hierarchically; For example, the sequence 1.3.6.1.5.5.7.3.1 identifies the Server Authentication extended-key usage. Those sequences, called OIDs (object identifiers) are assigned by the authorized organization (IANA, ISO and ITU-T).

The most commonly used Certificate file format today is the PKCS#12 (personal information exchange standard) format. This standard permits you to prepare a X509 certificate file that may contain the private key as well, encrypted with a secret password. This is easiest imagined as a bag that contains the X509 certificate and the encrypted private key.

Manage X509 Certificates Stores with .NET Framework

The .NET classes involved on the X509 certificate management are those under the System.Security.Cryptography.X509Certificates namespace.

Before it can be used, a digital certificate must be located and loaded. X509 certificates are stored on Microsoft® Windows machines in a container that can be browsed with certmgr.msc command. Launching the command,  you will see something like this:

This shows the so called “current user” certificate container, the container associated with the user currently logged on the machine. The “Personal” subfolder contains one certificate with a ‘friendly name’ given by webmail.

X509 certificates can be stored on a ‘per machine’ basis too. To open the certificate container for a local or remote machine, run mmc.exe and add the certificates snap-in, selecting the computer you want to administer.

Within the .NET Framework base classes, a subfolder is called “store”. A certificates store can be opened utilizing the X509Store class:

X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);

store.Open(OpenFlags.OpenExistingOnly);

In this example, the “current user” container is opened and the certificates that reside on the “Personal” store are loaded.

To open a store on the “local machine” container, you must change the StoreLocation enumeration value with the value:

StoreLocation.LocalMachine

The store that you wish to open is set with the StoreName enumeration. Others enumeration values allow you to select other stores inside the container. These are stores related to the X509 certificates that are issued to other entities involved in the PKI system. Those are beyond the scope of this article.

 

Notice now the Open method. This accepts, as an input parameter, an OpenFlags enumeration value given by OpenExistingOnly. This states that the Open method can only open an existing store inside the container. It might seem to imply to you that stores can be created too. And you’d be right.  Using the appropriate override of the X509Store class constructor, a new store can be created:

X509Store store = new X509Store(“MyStore”, StoreLocation.CurrentUser);

store.Open(OpenFlags.ReadWrite);

In this example, a new store named “MyStore” is created and opened for read write operations.

Notice that, if a new store is created, the .NET Framework doesn’t allow you to remove it anymore. There is no method that permits a store deletion. It can be deleted only with another tool such as CAPICOM or by using Microsoft® CryptoAPI directly.

It’s time now to work with certificates on the stores. To do so, the X509Store class provides a Certificates property of type X509Certificate2Collection:

X509Certificate2Collection certificates = store.Certificates;

The certificates object now contains all the certificates stored on the opened store. A certificate can be retrieved from the collection with the following code:

X509Certificate2 certificate = certificates[n];

with n being the selected index.

A certificate can also be loaded from a certificate file:

X509Certificate2 myCertificate = new X509Certificate2(“c:\....\mycertificate.pfx”);

and then saved into the opened store:

store.Add(myCertificate);

Finally, a certificate can be removed from a store with the method:

store.Remove(certificates[n]);

Manage X509 Certificates with .NET Framework

The X509Certificate2 class allows you to manage the “certificate data units” programmatically. First of all, notice the suffix 2 on the class name. This happens because the X509Certificate2 class extends methods and properties of its base class, the X509Certificate class. It extends the X509Certificate class by allowing, above all, the management of the private key (if  present, as seen for the PKCS#12 certificate format), and the browsing of the X509 v3 extensions.

The X509Certificate2 class allows you to retrieve, from the certificate that is loaded, its representative data through a set of properties. Among them:

Name

Type

Description

Issuer

string

Identify the issuer of the certificate (the certification authority that signed the certificate).

Subject

string

Identify the  subject, owner of the private key.

NotBefore

DateTime

It states that the certificate can be used only after the NotBefore data.

NotAfter

DateTime

It states that the certificate can be used  until the NotAfter data.

PublicKey

PublicKey

Represents the Public Key associated to the subject.

Extensions

X509ExtensionCollection

Collection of X509 v3 extensions.

In those, the public key is retrieved as a PublicKey object. This object contains all the information related to the public key itself, but this information are  not easy to explain in this article because the reader would require a knowledge of asymmetric cryptographic algorithms, ASN.1 encoding rules and OID assignment.

You can however get a string representation of the public hey by utilizing a X509Certificate class method, from which X509CertificateClass2 derives:

string publicKey = certificate.GetPublicKeyString();

The publicKey string now contains the same string representation of the public key seen on the first image proposed on this article (without white spaces).

The X509 v3 Extensions can be analyzed through browsing on the collection elements. Those are of type X509Extension. This type defines the OID assigned to the related extension and its ASN.1 encoded value.

Performing Signatures with the .NET Framework

To perform a signature using an X509 certificate and .NET Framework base classes, the X509 certificate must have the private key too. In fact, as stated previously, a signature consists of an encryption with the private key (that must be present) of hashes computed on messages to sign.  If an object of type X509Certificate2 has the private key (due to the fact that the PKCS#12 file imported on the store has the private key). This can be retrieved with the following code:

AsymmetricAlgorithm privateKey = certificate.PrivateKey;

You'll have noticed the type of PrivateKey property.  It is of type  AsymmetricAlgorithm, a class that can be found under the System.Security.Cryptography namespace. Is seems to have nothing to do with private keys. But remember that the private key is an element, inside the PKI elements, that require an high level of protection. When importing a PKCS#12 file into your X509 store, the private key became a more complex “object” inside the store, in the sense that it is saved  “keeping in mind the purpose of the same and its protection requirements”. It need an unique identifier to search for it, it need protection against attacker, it need access control, it need a suitable, but flexible, storage. Without  entering more deeply on the argument, think of this object as  a sort of “pipeline” between your code and the cryptographic subsystem of your operating system that manages, in a secure way, all the cryptographic operation based on your key pairs.

In reality, the AsymmetricAlgorithm class is only a base class of more complex classes. It is the base class for all the classes that implement specific asymmetric algorithms standards. Today, a widely-adopted standard for digital signature is RSA asymmetric encryption with SHA-1 hash algorithm. If the certificate contains RSA asymmetric keys pairs, the previous method does not, as one might expect, return an AsymmetricAlgorithm object, but an RSACryptoServiceProvider object, whose class derives from the AsymmetricAlgorithm class. The RSACryptoServiceProvider class contains all the properties and methods that are related to what we said previously.

So, the next step is to cast the privateKey object to a RSACryptoServiceProvider object, or, in more elegant way:

RSACryptoServiceProvider privateKey

                          =  certificate.PrivateKey as RSACryptoServiceProvider;

Now a signature can be performed. To do so, the SignData method of the privateKey object can be used. It accepts, as input, (1) the data to sign, as array of bytes, and (2) the object that represents the hash algorithm to use:

byte[] buffer = Encoding.Default.GetBytes("Hello World ... !");

byte[] signature = privateKey.SignData(buffer, new SHA1Managed());

The signature can also be verified. To do so you must utilize the public key of the certificate.

RSACryptoServiceProvider publicKey

                        =  certificate.PublicKey.Key as RSACryptoServiceProvider;

 

bool verify = publicKey.VerifyData

                        (buffer, new SHA1Managed(), signature);

From the above example you see that the certificate.PublicKey.Key property is again an object of type AsymmetricAlgortihm. This is for the same reasons seen for the private key.

The certificate to use for the verification can be the same certificate used for the generation of the signature but even a version of it that contains only the public key. No private key is required. And this is what always happens. Remember that the recipient receive only the signed message plus the certificate without the private key, that remain secret and accessible only by its owner. This means that verifications occurs always with the utilization of the public key “extracted” from a certificate that doesn’t have private key.

Another way to perform signature is to use the class RSAPKCS1SignatureFormatter. It brings to the same result of the previous method. To do so, the hash of data to sign must be computed first:

byte[] buffer = Encoding.Default.GetBytes("Hello World ... !");

byte[] hash = SHA1Managed.Create().ComputeHash(buffer);

RSAPKCS1SignatureFormatter formatter

                    = new  RSAPKCS1SignatureFormatter(certificate.PrivateKey);

formatter.SetHashAlgorithm("SHA1");

signature = formatter.CreateSignature(hash);

To verify the signature, use the RSAPKCS1SignatureDeformatter class:

RSAPKCS1SignatureDeformatter deformatter

                    = new RSAPKCS1SignatureFormatter(certificate.PublicKey.Key);

deformatter.SetHashAlgorithm("SHA1");

bool verify = formatter.VerifySignature(hash,signature);

Conclusion

This article gave an outline of what a digital signature is, and how to digitally sign data with the .NET Framework. Digital signatures, and cryptographic services in general, are very complex subjects and  are not easy to summarize. If you feel we haven't really helped to make it clearer for you, please say so by leaving a comment to this article and even ask the author for other articles on the subject, indicating what you would like to read more about.

If you would like to experiment digital signatures with X509 certificate, probably you need some X509 certificate for testing. We end this paper by providing you some way to gets digital certificates:

  • You can download the openssl projects files at The OpenSSL Project and set up a smart certification authority.

  • You can use makecert.exe command  (see Certificate Creation Tool (Makecert.exe) ) that you can find on Microsoft® Windows SDK.

  • You can generate X509 certificate on-line using X509 Builder web application at the author’s site  wecoffee.



This article has been viewed 22562 times.
Matteo Slaviero

Author profile: Matteo Slaviero

Matteo Slaviero works as Microsoft .NET Framework consultant. He recently started his own company, Cassandra, to develop new products and services related to the world of cryptography (symmetric encryption, digital signature, X509 digital certificates generation and more). . Follow him on Twitter

Search for other articles by Matteo Slaviero

Rate this article:   Avg rating: from a total of 56 votes.


Poor

OK

Good

Great

Must read
 
Have Your Say
Do you have an opinion on this article? Then add your comment below:
You must be logged in to post to this forum

Click here to log in.


Subject: Reg:Digitally signing a document using smartcard in asp.net application
Posted by: Ramba (view profile)
Posted on: Wednesday, October 28, 2009 at 11:24 PM
Message: Thaks for your helpful article.I am having slightly different requirment.

In my web application ,i wanted to digitally sign a document using smartcard at the client side and verification at the server side.

What technique/tool i can use for this requirement?

please give me your valuable Ideas /suggessions.

Thanks and regards,

Ramba

Subject: RE:Digitally signing a document using smartcard in asp.net application
Posted by: conseguenza (view profile)
Posted on: Friday, October 30, 2009 at 2:03 AM
Message: Hi Ramba, thanks for your appreciation.
For your web application, it depend on the type of document that you want to sign. To sign your document and to verify it server side, the document plus the public key related to the private key that signed the document must be send to the server. For document as PDF and doc, they have already a format for the public key insertion on the document. The validation server side can be made using the sdk of those document.
If you need to generate document on client, allowing their signature programmatically, you must use tools that work on web page client side. You can use CAPICOM activex to do so. You must send the signed document to the client plus the public key (as raw data) and then verify it. In this case, the X509Certificate2 object must be created in this way: assuming that the certificate's raw data are passed as bytes array (rawData). Then:
X509Certificate2 certificate = new X509Certiifcate2();
certificare.Import(rawData);
Then you can follow the instruction on the article.
I hope that those information will be usefull.

Subject: Sign PDF files..
Posted by: Shaqil (not signed in)
Posted on: Thursday, November 05, 2009 at 6:14 AM
Message: hi..
i want to sign pdf documents through my web application on client side...
issue is how to i deploye the functionality at client side for signing...

Subject: Sign PDF files..
Posted by: Shaqil (not signed in)
Posted on: Thursday, November 05, 2009 at 6:29 AM
Message: hi..
i want to sign pdf documents through my web application on client side...
issue is how to i deploye the functionality at client side for signing...

Subject: RE:Sign PDF files ...
Posted by: conseguenza (view profile)
Posted on: Friday, November 06, 2009 at 1:07 AM
Message: Hi Shaqil, see the reply sent to Ramba.

Subject: Digital Signatures in Silverlight
Posted by: Andrzej (view profile)
Posted on: Monday, November 09, 2009 at 2:49 AM
Message: Hi Matteo,
How use digital signature in Silverlight v3?
Is possible direct using in SL3?
Thx, Andrzej

Subject: Digital Signatures in Silverlight
Posted by: Andrzej (view profile)
Posted on: Monday, November 09, 2009 at 3:23 AM
Message: Hi Matteo,
How use digital signature in Silverlight v3?
Is possible direct using in SL3?
Thx, Andrzej

Subject: RE: Digital Signatures in Silverlight
Posted by: conseguenza (view profile)
Posted on: Monday, November 09, 2009 at 11:40 AM
Message: Hi Andrzej, actually I don't use Silverlight and so I cannot help you. Sorry.

Subject: How to digitally sign an email
Posted by: rahulanand (view profile)
Posted on: Thursday, January 21, 2010 at 11:15 PM
Message: Hi Matteo,
Thanks for the wonderful article.
I need to your help.

We have a requirement where a logged in user of a asp.net application send a request to the admin. Request is a simple mail to the admin for user need. Like a user wants to change his name,address etc. User simply login to application fill a form and then click a submit button which internally send a mail to admin. If the mail is send properly, user is prmted "Your request has been send".

How to digitallly sign that mail(request)?
Please help ....

Subject: RE: How ro digitally sign an email
Posted by: conseguenza (view profile)
Posted on: Tuesday, January 26, 2010 at 12:56 PM
Message: Hi rahulanand, thanks for your appreciation.
I need more datails to be able to reply to you. If you want you can write to me at matteo.slaviero@we-cassandra.com explaining me at least how your page works, who must sign the mail and how you generate the certificate for the signer.

Subject: Approach on using 2 certificates on 2 different Applications
Posted by: Umesh (view profile)
Posted on: Thursday, February 25, 2010 at 7:35 AM
Message: Hi Matteo,

Really a nice explanation for the begineers.
What I need to know is we have 2 applications, let's say APP1 and APP2, so APP1 would have its own certificate and APP2 would have it's own certificate, APP1 encrypts the message with it's private key and also adds a public key along with the message for the APP2 to decrypt it, that means APP1 would have his certifcate in the Personal Store, also APP2 would use its own private key to sign the message and send the same to APP1, now I guess APP1 would also need to have APP2's certificate installed on his local machine so that the messages can be decrypted using the public key, my questions are as below;

1) In which store the APP2 certificate should be stored on APP1's local machine

2) Also, if you could pass on me the link to some article, code sample of how the above scenario can be implemented.

Thanks Again

Subject: RE:Approach on using 2 certificates on 2 different Applications
Posted by: conseguenza (view profile)
Posted on: Monday, March 01, 2010 at 3:50 AM
Message: Hi Umesh,
thanks you for your appreciation.
About you issue keep in mind that, while the private key must be keep secret, the public key can be freely redistribute in any you want form.
This means that, every mechanism that is able to get a public key to verify a signature is acceptable. And it means also that every mechanism that is able to share the public key to other entities is acceptable too.
Being you the software developer, you can use any mechanism that you like as long as it keep the secret key private.
If only two application are involved you can store:
APP1 machine: the APP1 certificate with private key, the APP2 certificate with only the APP2’s public key.
APP2 machine: the APP2 certificate with private key, the APP1 certificate with only the APP1’s public key.
They also need the certification authority’s certificate that signed the certificate installed on them.
To verify the APP1 signature on the APP2 machine you can load the APP1 certificate from the APP2 machine and vice versa.
The personal store or machine store depend only on which user need the certificate. If a single user, you should use the personal store, if multiple users, the machine store.
If you want to extend your system to other machines, the best way is not to install the certificate of every machine in each machine but to share the digital signed message with the certificate inside it. This is the solution that I think you should prefers. To do so the PKCS#7 standard was developed. To use it, the System.Security.Cryptography.Pkcs namespace of .NET framework has all object that you need.

Subject: Need Help in Verifying using
Posted by: raju.all4u (view profile)
Posted on: Friday, March 26, 2010 at 1:16 AM
Message: Hi Conseguenza,

Thanks for such a great article. Its only your article that explains complex things in a simple way. So I am able to do experiment on digital signature using certificate.

I have one doubt. I build a certificate using http://www.we-coffee.com/x509Builder.aspx. I got 2 certificates.
1. B7097euc.pfx: This file represents the digital signature certificate that can be used for any purposes involving digital signatures. An End User Certificate (EUC) containing the public and private keys (.PFX) related to the service that you choose to implement.
2. 8B48Eica.p12: This file represents the Certificate Authority file that signed your certificate. An Internal Certification Authority (ICA) certificate that correspond to the certificate that signed the end user certificate. It contains only the public key (.P12).

The EUC certificate can be used for the purpose related to the certificate itself. The ICA certificate must be used to validate the EUC certificate. It must be installed on every client consuming the service related to the EUC certificate generated.

My problem is that I am able to sign & verify using the first file. However I am fail to verify a message(signed using 1st file) using 2nd file's public key. I suppose 2nd file has public key related with the first file.

Please comment. I am desperately waiting for your response.

Thanks

Subject: Need Help in Verifying using
Posted by: raju.all4u (view profile)
Posted on: Friday, March 26, 2010 at 1:41 AM
Message: Hi Conseguenza,

Thanks for such a great article. Its only your article that explains complex things in a simple way. So I am able to do experiment on digital signature using certificate.

I have one doubt. I build a certificate using http://www.we-coffee.com/x509Builder.aspx. I got 2 certificates.
1. B7097euc.pfx: This file represents the digital signature certificate that can be used for any purposes involving digital signatures. An End User Certificate (EUC) containing the public and private keys (.PFX) related to the service that you choose to implement.
2. 8B48Eica.p12: This file represents the Certificate Authority file that signed your certificate. An Internal Certification Authority (ICA) certificate that correspond to the certificate that signed the end user certificate. It contains only the public key (.P12).

The EUC certificate can be used for the purpose related to the certificate itself. The ICA certificate must be used to validate the EUC certificate. It must be installed on every client consuming the service related to the EUC certificate generated.

My problem is that I am able to sign & verify using the first file. However I am fail to verify a message(signed using 1st file) using 2nd file's public key. I suppose 2nd file has public key related with the first file.

Please comment. I am desperately waiting for your response.

Thanks

Subject: RE:Need Help in Verifying using
Posted by: conseguenza (view profile)
Posted on: Friday, March 26, 2010 at 2:42 AM
Message: Hi Raju
thanks for your appreciation.
About your question.
You cannot use the second certificate (...ica.p12) to verify a message generated with the first certificate (...euc.pfx).
The first certificate sign and verify your message, the second certificate is the CA certifcate that issue the EUC certificate.
It is used only to verify that the EUC certificate was issued by a trusted entity.
Suppose you are the user A and you want to sign a message to send to the user B. With the private key (contained on the ...euc.pfx certificate) you signed the message and you send the signed message plus the public key contained on the ...euc.pfx to B. B verifies your signature. For that it can use only the public key on the ...euc.pfx certificate. Every other public key invalidate the signature.
But there is a problem. How B can be sure that the message is sent by A ? An entity, say C, can generate your own certificate, saying that it is A, and send to B a signed message impersonating A. How can B be sure that the public key (and the message) that received is the A public key (and the message was sent by A) ? It need a third entity, that it trusts, that assures that the certificate is really the A certificate. This entity is said certificate authority. It has the responsibility to assure B that the certificate received is the A's certificate. So it take the A public key and signs it with its private key. When B receives the message, it verifies the signature with the public key received and it verifies with the CA public key (the ...ica.p12 certificate) that the A certificate (the ...euc.pfx) is really the A certificate (by verifing the signature on it computed by the CA). So, the goal of the ..ica.p12 certificate is only to verify the signature on the ...euc.pfx certificate, not to verify messages signed by the ...euc.pfx. For more details you can read http://www.we-coffee.com/knowledge/BIB_R5YWR.aspx.
Hope this will be helpful

Subject: Need Help in Verifying using
Posted by: raju.all4u (view profile)
Posted on: Friday, March 26, 2010 at 3:43 AM
Message: Hi Conseguenza,

Thanks for such a great article. Its only your article that explains complex things in a simple way. So I am able to do experiment on digital signature using certificate.

I have one doubt. I build a certificate using http://www.we-coffee.com/x509Builder.aspx. I got 2 certificates.
1. B7097euc.pfx: This file represents the digital signature certificate that can be used for any purposes involving digital signatures. An End User Certificate (EUC) containing the public and private keys (.PFX) related to the service that you choose to implement.
2. 8B48Eica.p12: This file represents the Certificate Authority file that signed your certificate. An Internal Certification Authority (ICA) certificate that correspond to the certificate that signed the end user certificate. It contains only the public key (.P12).

The EUC certificate can be used for the purpose related to the certificate itself. The ICA certificate must be used to validate the EUC certificate. It must be installed on every client consuming the service related to the EUC certificate generated.

My problem is that I am able to sign & verify using the first file. However I am fail to verify a message(signed using 1st file) using 2nd file's public key. I suppose 2nd file has public key related with the first file.

Please comment. I am desperately waiting for your response.

Thanks

Subject: Need Help in Verifying using
Posted by: raju.all4u (view profile)
Posted on: Friday, March 26, 2010 at 3:53 AM
Message: Hi Conseguenza,

Thanks a lot for your explanation. I appreciate your approach of answering.

Thanks once again.
Raju Ansari

Subject: What are methods to distribute public key?
Posted by: raju.all4u (view profile)
Posted on: Friday, March 26, 2010 at 3:59 AM
Message: Hi All,

What are methods to distribute once public key? And how do a receiver verify it? I know they get it verified from CA, but for this they might need "An Internal Certification Authority (ICA) certificate that correspond to the certificate that signed the end user certificate. It contains only the public key (.P12)". How a receiver gets the ICA files?

Thanks,
Raju Ansari

Subject: RE:What are methods to distribute public key?
Posted by: conseguenza (view profile)
Posted on: Friday, March 26, 2010 at 4:32 AM
Message: In Microsoft operating system the trusted ca certificate are stored on the certificate store under the section "trusted root certification authorities". (you can open it using the command certmgr.msc). All the certificate stored under this node are considered valid for certificate validation.
The trusted root certification authorities contains:
1. commercial ca certificate. They are inserted by Microsoft and are related to commercial ca
2. own ca (internal certificate authority (ICA) certificates) they are inserted by the user and are related to certificate authority built for example inside an organization.
To validate your euc.pfx certificate you need only to manually install the ica.p12 certificate on this store. To do so, double click on the certificate file and follow the instruction that appears. The wizard will recognize the certificate as ca certificate and will insert it in the trusted root certification authorities (The euc.pfx certificate will go under the personal store). When the wizard will ask the password to install the ica.p12 certificate, leave it blank. The certificate has no the private key and does not need to be protected.

Keep in mind that others vendor may use different certificate store for the ca certificate. They works all in the same way. The commercial ca are already on the store, personal ca must be installed on it. This is the case for example, of all browsers different form internet explorer and acrobat reader. Check the products documentation to understand how to install the ica.p12 certificate as trusted ca certificate.

Hope this can help you.

Subject: using certificate stored in usb token/smart card
Posted by: selmaguzel (view profile)
Posted on: Sunday, May 09, 2010 at 10:27 AM
Message: Hi,

I have read your great article about digital signatures(http://www.simple-talk.com/dotnet/.net-framework/beginning-with-digital-signatures-in-.net-framework/).

I haven't any experiment about this topic and I do need your help.

What I want to achieve is that I want to sign a document using the certificate stored in a usb token/smart card(This usb token will be bought from a trusted certificate authority.) In addition, the same document should be signed by multiple users. How can I do this? I have researced for a while. However, I haven't been able to find an exact solution. The Capicom2 dll is suggested for this, but I haven't been able to find a simple sample.


Could you send a sample for signing and verifying a document using the best way you suggest?

Thanks for your help.

Yours sincerely.

Selma GUZEL

Subject: RE:using certificate stored in usb token/smart card
Posted by: conseguenza (view profile)
Posted on: Monday, May 10, 2010 at 2:45 AM
Message: Hi Selma,
thank for your appreciation about my article.

About your issue, yes, CAPICOM is the right way to perform multiple digital signature. It uses PKCS#7 standard that is a standard that permits to exchange cryptographic information. I cannot say to you how to do multiple digital signature, for a simple reason. In my site, we-coffee.com I propose a dll, Bonnie.NET Web Edition, that permits to perform multiple digital signatures both from server side that from a web page. For details see http://www.we-coffee.com/bonnie-web.aspx. So I cannot reveal to you “secrets” inside it.
If you need to perform multiple digital signature, try Bonnie.NET Web Edition and eventually let me know your thinks.

Subject: Verification problem.
Posted by: Vaggan (view profile)
Posted on: Monday, January 03, 2011 at 9:05 AM
Message: Hi,
Thanks for a great article.

I have a question:
I have a .msi file that is certified by SignTool.
How can I verify that it has a valid certificate and that the file has been tampered with?

I can get certificatet and publickey from the file but after that I'm stuck.

Thanks,
Vaggan

Subject: Good Work!!!
Posted by: rk_sweetrascal (view profile)
Posted on: Thursday, January 13, 2011 at 2:33 AM
Message: Hey.... good one!!! i hav one pblm.
Two applications hav to be developed using c#.One is for the sender and another one is for the receiver. The sender sends the file by clicking command button, the file must automatically get encrypted (using digital signatures) and sent through the internet and in the receiving side, verification, the receiver enters the password and gets access to the file.While transmitting the file should look like a fake document. this is my pblm. please assist me. mail me at r.k.prabakar1987@gmail.com

Subject: using digital certificate stored in usb token
Posted by: SenaReddy (view profile)
Posted on: Sunday, October 16, 2011 at 7:55 AM
Message: Greate artical

What I want to achieve is that I want to sign a document using the certificate stored in a usb token(This usb token will be bought from a trusted certificate authority.) In addition, the same document should be signed by multiple users. How can I do this(in asp.net)?

I am new to this. Please help me.

Thanks.


Subject: Private key is to DECRYPT and Public key is to ENCRYPT
Posted by: ivanzinho (view profile)
Posted on: Friday, January 27, 2012 at 3:09 PM
Message: Hello.
Reading the first paragraph of this tutorial I found this concept is not well defined. Browsing in the web I found in ALL pages that Private key is to DECRYPT messages and Public key is to ENCRYPT them.

 






recommended site pinvoke

PInvoke.net is a user-driven wiki which provides .NET developers with native method signatures, so they don't have to spend time writing them from scratch.




TortoiseSVN and Subversion Cookbook Part 3: In, Out, and Around
 Subversion doesn't have to be difficult, especially if you have Michael Sorens's guide at hand. After... Read more...

Feature Usage Reporting in Early Access Programs
 After doing Web development, you can get very used to the luxury of having basic information about your... Read more...

Feature Usage Reporting in Early Access Programs
 After doing Web development, you can get very used to the luxury of having basic information about your... Read more...

TLS/SSL and .NET Framework 4.0
 The Secure Socket Layer is now essential for the secure exchange of digital data, and is most generally... Read more...

SmartAssembly: Eating Our Own Dogfood
 Quite often at Red Gate, we are some of our own most enthusiastic software-users. SmartAssembly is a... Read more...

A Complete URL Rewriting Solution for ASP.NET 2.0
 Ever wondered whether it's possible to create neater URLS, free of bulky Query String parameters?... Read more...

Visual Studio Setup - projects and custom actions
 This article describes the kinds of custom actions that can be used in your Visual Studio setup project. Read more...

.NET Application Architecture: the Data Access Layer
 Find out how to design a robust data access layer for your .NET applications. Read more...

Web Parts in ASP.NET 2.0
 Most Web Parts implementations allow users to create a single portal page where they can personalize... Read more...

Configuring Forms Authentication in SharePoint 2007
 Damon Armstrong provides a step-by-step guide to the processes, quirks and pitfalls of setting up... Read more...

Over 400,000 Microsoft professionals subscribe to the Simple-Talk technical journal. Join today, it's fast, simple, free and secure.

Join Simple Talk