ECDsaCng Class
Provides a Cryptography Next Generation (CNG) implementation of the Elliptic Curve Digital Signature Algorithm (ECDSA).
System.Security.Cryptography.AsymmetricAlgorithm
System.Security.Cryptography.ECDsa
System.Security.Cryptography.ECDsaCng
Namespace: System.Security.Cryptography
Assembly: System.Core (in System.Core.dll)
The ECDsaCng type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | ECDsaCng() | Initializes a new instance of the ECDsaCng class with a random key pair. |
![]() | ECDsaCng(CngKey) | Initializes a new instance of the ECDsaCng class by using the specified CngKey object. |
![]() | ECDsaCng(Int32) | Initializes a new instance of the ECDsaCng class with a random key pair, using the specified key size. |
| Name | Description | |
|---|---|---|
![]() | HashAlgorithm | Gets or sets the hash algorithm to use when signing and verifying data. |
![]() | Key | Gets or sets the key to use when signing and verifying data. |
![]() | KeyExchangeAlgorithm | Gets the name of the key exchange algorithm. (Inherited from ECDsa.) |
![]() | KeySize | Gets or sets the size, in bits, of the key modulus used by the asymmetric algorithm. (Inherited from AsymmetricAlgorithm.) |
![]() | LegalKeySizes | Gets the key sizes that are supported by the asymmetric algorithm. (Inherited from AsymmetricAlgorithm.) |
![]() | SignatureAlgorithm | Gets the name of the signature algorithm. (Inherited from ECDsa.) |
| Name | Description | |
|---|---|---|
![]() | Clear | Releases all resources used by the AsymmetricAlgorithm class. (Inherited from AsymmetricAlgorithm.) |
![]() | Dispose() | Releases all resources used by the current instance of the AsymmetricAlgorithm class. (Inherited from AsymmetricAlgorithm.) |
![]() | Equals(Object) | Determines whether the specified object is equal to the current object. (Inherited from Object.) |
![]() | FromXmlString(String) | This method is not implemented. (Overrides AsymmetricAlgorithm.FromXmlString(String).) |
![]() | FromXmlString(String, ECKeyXmlFormat) | Deserializes the key information from an XML string by using the specified format. |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | SignData(Byte[]) | Generates a signature for the specified data. |
![]() | SignData(Stream) | Generates a signature for the specified data stream, reading to the end of the stream. |
![]() | SignData(Byte[], Int32, Int32) | Generates a digital signature for the specified length of data, beginning at the specified offset. |
![]() | SignHash | Generates a signature for the specified hash value. (Overrides ECDsa.SignHash(Byte[]).) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
![]() | ToXmlString(Boolean) | This method is not implemented. (Overrides AsymmetricAlgorithm.ToXmlString(Boolean).) |
![]() | ToXmlString(ECKeyXmlFormat) | Serializes the key information to an XML string by using the specified format. |
![]() | VerifyData(Byte[], Byte[]) | Verifies the digital signature of the specified data. |
![]() | VerifyData(Stream, Byte[]) | Verifies the digital signature of the specified data stream, reading to the end of the stream. |
![]() | VerifyData(Byte[], Int32, Int32, Byte[]) | Verifies a signature for the specified length of data, beginning at the specified offset. |
![]() | VerifyHash | Verifies the specified digital signature against a specified hash value. (Overrides ECDsa.VerifyHash(Byte[], Byte[]).) |
This class derives from the ECDsa abstract base class.
Note |
|---|
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"); } } }
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.
