This documentation is archived and is not being maintained.

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 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.

This class derives from the ECDsa abstract base class.

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");
                Console.WriteLine("Data is bad");

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

Windows 7, Windows Vista, Windows Server 2008 R2, Windows Server 2008

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

.NET Framework

Supported in: 3.5