Export (0) Print
Expand All

ECDsaCng Class

Provides a Cryptography Next Generation (CNG) implementation of the Elliptic Curve Digital Signature Algorithm (ECDSA).

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

[HostProtectionAttribute(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
public sealed class ECDsaCng : ECDsa

The ECDsaCng type exposes the following members.

  NameDescription
Public methodECDsaCng()Initializes a new instance of the ECDsaCng class with a random key pair.
Public methodECDsaCng(CngKey)Initializes a new instance of the ECDsaCng class by using the specified CngKey object.
Public methodECDsaCng(Int32)Initializes a new instance of the ECDsaCng class with a random key pair, using the specified key size.
Top

  NameDescription
Public propertyHashAlgorithmGets or sets the hash algorithm to use when signing and verifying data.
Public propertyKeyGets or sets the key to use when signing and verifying data.
Public propertyKeyExchangeAlgorithmGets the name of the key exchange algorithm. (Inherited from ECDsa.)
Public propertyKeySizeGets or sets the size, in bits, of the key modulus used by the asymmetric algorithm. (Inherited from AsymmetricAlgorithm.)
Public propertyLegalKeySizesGets the key sizes that are supported by the asymmetric algorithm. (Inherited from AsymmetricAlgorithm.)
Public propertySignatureAlgorithmGets the name of the signature algorithm. (Inherited from ECDsa.)
Top

  NameDescription
Public methodClearReleases all resources used by the AsymmetricAlgorithm class. (Inherited from AsymmetricAlgorithm.)
Public methodDispose()Releases all resources used by the current instance of the AsymmetricAlgorithm class. (Inherited from AsymmetricAlgorithm.)
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodFromXmlString(String)This method is not implemented. (Overrides AsymmetricAlgorithm.FromXmlString(String).)
Public methodFromXmlString(String, ECKeyXmlFormat)Deserializes the key information from an XML string by using the specified format.
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodSignData(Byte[])Generates a signature for the specified data.
Public methodSignData(Stream)Generates a signature for the specified data stream, reading to the end of the stream.
Public methodSignData(Byte[], Int32, Int32)Generates a digital signature for the specified length of data, beginning at the specified offset.
Public methodSignHashGenerates a signature for the specified hash value. (Overrides ECDsa.SignHash(Byte[]).)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodToXmlString(Boolean)This method is not implemented. (Overrides AsymmetricAlgorithm.ToXmlString(Boolean).)
Public methodToXmlString(ECKeyXmlFormat)Serializes the key information to an XML string by using the specified format.
Public methodVerifyData(Byte[], Byte[])Verifies the digital signature of the specified data.
Public methodVerifyData(Stream, Byte[])Verifies the digital signature of the specified data stream, reading to the end of the stream.
Public methodVerifyData(Byte[], Int32, Int32, Byte[])Verifies a signature for the specified length of data, beginning at the specified offset.
Public methodVerifyHashVerifies the specified digital signature against a specified hash value. (Overrides ECDsa.VerifyHash(Byte[], Byte[]).)
Top

This class derives from the ECDsa abstract base class.

NoteNote

The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: MayLeakOnAbort. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

The following example shows how to use the ECDsaCng class to sign a message and how to use the signature to verify that the message has not been altered.

using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;


class Alice
{
    public static void Main(string[] args)
    {
        Bob bob = new Bob();
        using (ECDsaCng dsa = new ECDsaCng())
        {
            dsa.HashAlgorithm = CngAlgorithm.Sha256;
             bob.key = dsa.Key.Export(CngKeyBlobFormat.EccPublicBlob);

             byte[] data = new byte[] { 21, 5, 8, 12, 207 };

             byte[] signature = dsa.SignData(data);

             bob.Receive(data, signature);
            }
    }


}
public class Bob 
{
    public byte[] key;

    public void Receive(byte[] data, byte[] signature)
    {
        using (ECDsaCng ecsdKey = new ECDsaCng(CngKey.Import(key, CngKeyBlobFormat.EccPublicBlob)))
        {
            if (ecsdKey.VerifyData(data, signature))
                Console.WriteLine("Data is good");
            else
                Console.WriteLine("Data is bad");
        }
    }
}

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5

.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