Export (0) Print
Expand All

SignatureDescription Class

Contains information about the properties of a digital signature.

Namespace:  System.Security.Cryptography
Assembly:  mscorlib (in mscorlib.dll)

[ComVisibleAttribute(true)]
public class SignatureDescription

The SignatureDescription type exposes the following members.

  NameDescription
Public methodSignatureDescription()Initializes a new instance of the SignatureDescription class.
Public methodSignatureDescription(SecurityElement)Initializes a new instance of the SignatureDescription class from the specified SecurityElement.
Top

  NameDescription
Public propertyDeformatterAlgorithmGets or sets the deformatter algorithm for the signature description.
Public propertyDigestAlgorithmGets or sets the digest algorithm for the signature description.
Public propertyFormatterAlgorithmGets or sets the formatter algorithm for the signature description.
Public propertyKeyAlgorithmGets or sets the key algorithm for the signature description.
Top

  NameDescription
Public methodCreateDeformatterCreates an AsymmetricSignatureDeformatter instance with the specified key using the DeformatterAlgorithm property.
Public methodCreateDigestCreates a HashAlgorithm instance using the DigestAlgorithm property.
Public methodCreateFormatterCreates an AsymmetricSignatureFormatter instance with the specified key using the FormatterAlgorithm property.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

The following code example demonstrates how to use members of the SignatureDescription class.

using System;
using System.Security;
using System.Security.Cryptography;

class SignatureDescriptionImpl
{
    [STAThread]
    static void Main(string[] args)
    {
        // Create a digital signature based on RSA encryption.
        SignatureDescription rsaSignature = CreateRSAPKCS1Signature();
        ShowProperties(rsaSignature);

        // Create a digital signature based on DSA encryption.
        SignatureDescription dsaSignature = CreateDSASignature();
        ShowProperties(dsaSignature);

        // Create a HashAlgorithm using the digest algorithm of the signature.
        HashAlgorithm hashAlgorithm = dsaSignature.CreateDigest();
        Console.WriteLine("\nHash algorithm for the DigestAlgorithm property:"
            + " " + hashAlgorithm.ToString());

        // Create an AsymmetricSignatureFormatter instance using the DSA key.
        DSA dsa = DSA.Create();
        AsymmetricSignatureFormatter asymmetricFormatter =
            CreateDSAFormatter(dsa);

        // Create an AsymmetricSignatureDeformatter instance using the 
        // DSA key.
        AsymmetricSignatureDeformatter asymmetricDeformatter =
            CreateDSADeformatter(dsa);

        Console.WriteLine("This sample completed successfully; " +
            "press Enter to exit.");
        Console.ReadLine();
    }

    // Create a SignatureDescription for RSA encryption. 
    private static SignatureDescription CreateRSAPKCS1Signature()
    {
        SignatureDescription signatureDescription = 
            new SignatureDescription();

        // Set the key algorithm property for RSA encryption.
        signatureDescription.KeyAlgorithm =
            "System.Security.Cryptography.RSACryptoServiceProvider";

        // Set the digest algorithm for RSA encryption using the 
        // SHA1 provider.
        signatureDescription.DigestAlgorithm =
            "System.Security.Cryptography.SHA1CryptoServiceProvider";

        // Set the formatter algorithm with the RSAPKCS1 formatter.
        signatureDescription.FormatterAlgorithm =
            "System.Security.Cryptography.RSAPKCS1SignatureFormatter";

        // Set the formatter algorithm with the RSAPKCS1 deformatter.
        signatureDescription.DeformatterAlgorithm =
            "System.Security.Cryptography.RSAPKCS1SignatureDeformatter";

        return signatureDescription;
    }

    // Create a SignatureDescription using a constructed SecurityElement for  
    // DSA encryption. 
    private static SignatureDescription CreateDSASignature()
    {
        SecurityElement securityElement = new SecurityElement("DSASignature");

        // Create new security elements for the four algorithms.
        securityElement.AddChild(new SecurityElement(
            "Key",
            "System.Security.Cryptography.DSACryptoServiceProvider"));
        securityElement.AddChild(new SecurityElement(
            "Digest",
            "System.Security.Cryptography.SHA1CryptoServiceProvider")); 
        securityElement.AddChild(new SecurityElement(
            "Formatter",
            "System.Security.Cryptography.DSASignatureFormatter"));
        securityElement.AddChild(new SecurityElement(
            "Deformatter",
            "System.Security.Cryptography.DSASignatureDeformatter"));

        SignatureDescription signatureDescription = 
            new SignatureDescription(securityElement);

        return signatureDescription;
    }

    // Create a signature formatter for DSA encryption. 
    private static AsymmetricSignatureFormatter CreateDSAFormatter(DSA dsa)
    {
        // Create a DSA signature formatter for encryption.
        SignatureDescription signatureDescription = 
            new SignatureDescription();
        signatureDescription.FormatterAlgorithm =
            "System.Security.Cryptography.DSASignatureFormatter";

        AsymmetricSignatureFormatter asymmetricFormatter =
            signatureDescription.CreateFormatter(dsa);

        Console.WriteLine("\nCreated formatter : " + 
            asymmetricFormatter.ToString());
        return asymmetricFormatter;
    }

    // Create a signature deformatter for DSA decryption. 
    private static AsymmetricSignatureDeformatter CreateDSADeformatter(
        DSA dsa)
    {
        // Create a DSA signature deformatter to verify the signature.
        SignatureDescription signatureDescription = 
            new SignatureDescription();
        signatureDescription.DeformatterAlgorithm =
            "System.Security.Cryptography.DSASignatureDeformatter";

        AsymmetricSignatureDeformatter asymmetricDeformatter =
            signatureDescription.CreateDeformatter(dsa);

        Console.WriteLine("\nCreated deformatter : " + 
            asymmetricDeformatter.ToString());
        return asymmetricDeformatter;
    }

    // Display to the console the properties of the specified 
    // SignatureDescription. 
    private static void ShowProperties(
        SignatureDescription signatureDescription)
    {
        // Retrieve the class path for the specified SignatureDescription. 
        string classDescription = signatureDescription.ToString();

        string deformatterAlgorithm = 
            signatureDescription.DeformatterAlgorithm;
        string formatterAlgorithm = signatureDescription.FormatterAlgorithm;
        string digestAlgorithm = signatureDescription.DigestAlgorithm;
        string keyAlgorithm = signatureDescription.KeyAlgorithm;

        Console.WriteLine("\n** " + classDescription + " **");
        Console.WriteLine("DeformatterAlgorithm : " + deformatterAlgorithm);
        Console.WriteLine("FormatterAlgorithm : " + formatterAlgorithm);
        Console.WriteLine("DigestAlgorithm : " + digestAlgorithm);
        Console.WriteLine("KeyAlgorithm : " + keyAlgorithm);
    }
}
// 
// This sample produces the following output: 
//  
// ** System.Security.Cryptography.SignatureDescription ** 
// DeformatterAlgorithm : System.Security.Cryptography. 
// RSAPKCS1SignatureDeformatter 
//  
// FormatterAlgorithm : System.Security.Cryptography. 
// RSAPKCS1SignatureFormatter 
// DigestAlgorithm : System.Security.Cryptography.SHA1CryptoServiceProvider 
// KeyAlgorithm : System.Security.Cryptography.RSACryptoServiceProvider 
//  
// ** System.Security.Cryptography.SignatureDescription ** 
// DeformatterAlgorithm : System.Security.Cryptography.DSASignatureDeformatter 
// FormatterAlgorithm : System.Security.Cryptography.DSASignatureFormatter 
// DigestAlgorithm : System.Security.Cryptography.SHA1CryptoServiceProvider 
// KeyAlgorithm : System.Security.Cryptography.DSACryptoServiceProvider 
//  
// Hash algorithm for the DigestAlgorithm property:  
// System.Security.Cryptography.SH 
// A1CryptoServiceProvider 
//  
// Created formatter : System.Security.Cryptography.DSASignatureFormatter 
//  
// Created deformatter : System.Security.Cryptography.DSASignatureDeformatter 
// This sample completed successfully; press Enter to exit.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft