O'Reilly logo

Programming .NET Security by Allen Jones, Adam Freeman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Programming Digital Signatures

The .NET Framework groups encryption and digital signature algorithms together as subclasses of the AsymmetricAlgorithm class. Figure 16-4 depicts the .NET class hierarchy for digital signature algorithms, which differs from the encryption algorithm hierarchy only because of the addition of the signature-only DSA support.

The .NET Framework class hierarchy for digital signature algorithms

Figure 16-4. The .NET Framework class hierarchy for digital signature algorithms

The general lack of consistency between the abstract algorithm classes (RSA and DSA) and their implementation counterparts (RSACryptoServiceProvider and DSACryptoServiceProvider) means that there are several equivalent ways to accomplish signature operations, which we demonstrate in the following sections.

Using the Abstract Class

The abstract System.Security.Cryptography.DSA class defines the CreateSignature method, which accepts a SHA-1 hash code that will be PKCS #1 formatted and signed, as the following example demonstrates (we have omitted the process of specifying the key pair to use):

# C# // create the plaintext byte[] x_plaintext = Encoding.Default.GetBytes("Programming .NET Security"); // create the SHA-1 algorithm instance and create a hash code for the plaintext SHA1 x_sha = SHA1.Create( ); byte[] x_hashcode = x_sha.ComputeHash(x_plaintext); // create an instance of the DSA algorithm using // the Create method in the abstract class DSA x_dsa ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required