ECDsaCng Class
TOC
Collapse the table of content
Expand the table of content

ECDsaCng Class

.NET Framework (current version)
 

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

NameDescription
System_CAPS_pubmethodECDsaCng()

Initializes a new instance of the ECDsaCng class with a random key pair.

System_CAPS_pubmethodECDsaCng(CngKey)

Initializes a new instance of the ECDsaCng class by using the specified CngKey object.

System_CAPS_pubmethodECDsaCng(Int32)

Initializes a new instance of the ECDsaCng class with a random key pair, using the specified key size.

NameDescription
System_CAPS_pubpropertyHashAlgorithm

Gets or sets the hash algorithm to use when signing and verifying data.

System_CAPS_pubpropertyKey

Gets or sets the key to use when signing and verifying data.

System_CAPS_pubpropertyKeyExchangeAlgorithm

Gets the name of the key exchange algorithm.(Inherited from ECDsa.)

System_CAPS_pubpropertyKeySize

Gets or sets the size, in bits, of the key modulus used by the asymmetric algorithm.(Inherited from AsymmetricAlgorithm.)

System_CAPS_pubpropertyLegalKeySizes

Gets the key sizes that are supported by the asymmetric algorithm.(Inherited from AsymmetricAlgorithm.)

System_CAPS_pubpropertySignatureAlgorithm

Gets the name of the signature algorithm.(Inherited from ECDsa.)

NameDescription
System_CAPS_pubmethodClear()

Releases all resources used by the AsymmetricAlgorithm class.(Inherited from AsymmetricAlgorithm.)

System_CAPS_pubmethodDispose()

Releases all resources used by the current instance of the AsymmetricAlgorithm class.(Inherited from AsymmetricAlgorithm.)

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_pubmethodFromXmlString(String)

This method is not implemented.(Overrides AsymmetricAlgorithm.FromXmlString(String).)

System_CAPS_pubmethodFromXmlString(String, ECKeyXmlFormat)

Deserializes the key information from an XML string by using the specified format.

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodSignData(Byte[])

Generates a signature for the specified data.

System_CAPS_pubmethodSignData(Byte[], HashAlgorithmName)

Computes the hash value of the specified byte array using the specified hash algorithm and signs the resulting hash value. (Inherited from ECDsa.)

System_CAPS_pubmethodSignData(Byte[], Int32, Int32)

Generates a digital signature for the specified length of data, beginning at the specified offset.

System_CAPS_pubmethodSignData(Byte[], Int32, Int32, HashAlgorithmName)

Computes the hash value of a portion of the specified byte array using the specified hash algorithm and signs the resulting hash value. (Inherited from ECDsa.)

System_CAPS_pubmethodSignData(Stream)

Generates a signature for the specified data stream, reading to the end of the stream.

System_CAPS_pubmethodSignData(Stream, HashAlgorithmName)

Computes the hash value of the specified stream using the specified hash algorithm and signs the resulting hash value.(Inherited from ECDsa.)

System_CAPS_pubmethodSignHash(Byte[])

Generates a signature for the specified hash value.(Overrides ECDsa.SignHash(Byte[]).)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

System_CAPS_pubmethodToXmlString(Boolean)

This method is not implemented.(Overrides AsymmetricAlgorithm.ToXmlString(Boolean).)

System_CAPS_pubmethodToXmlString(ECKeyXmlFormat)

Serializes the key information to an XML string by using the specified format.

System_CAPS_pubmethodVerifyData(Byte[], Byte[])

Verifies the digital signature of the specified data.

System_CAPS_pubmethodVerifyData(Byte[], Byte[], HashAlgorithmName)

Verifies that a digital signature is valid by calculating the hash value of the specified data using the specified hash algorithm and comparing it to the provided signature. (Inherited from ECDsa.)

System_CAPS_pubmethodVerifyData(Byte[], Int32, Int32, Byte[])

Verifies a signature for the specified length of data, beginning at the specified offset.

System_CAPS_pubmethodVerifyData(Byte[], Int32, Int32, Byte[], HashAlgorithmName)

Verifies that a digital signature is valid by calculating the hash value of the data in a portion of a byte array using the specified hash algorithm and comparing it to the provided signature. (Inherited from ECDsa.)

System_CAPS_pubmethodVerifyData(Stream, Byte[])

Verifies the digital signature of the specified data stream, reading to the end of the stream.

System_CAPS_pubmethodVerifyData(Stream, Byte[], HashAlgorithmName)

Verifies that a digital signature is valid by calculating the hash value of the specified stream using the specified hash algorithm and comparing it to the provided signature. (Inherited from ECDsa.)

System_CAPS_pubmethodVerifyHash(Byte[], Byte[])

Verifies the specified digital signature against a specified hash value.(Overrides ECDsa.VerifyHash(Byte[], Byte[]).)

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

.NET Framework
Available since 3.5

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

Return to top
Show:
© 2016 Microsoft