Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ECDsaCng Class

Updated: March 2011

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)

'Declaration
<HostProtectionAttribute(SecurityAction.LinkDemand, MayLeakOnAbort := True)> _
Public NotInheritable Class ECDsaCng _
	Inherits ECDsa

The ECDsaCng type exposes the following members.

  NameDescription
Public methodECDsaCngInitializes 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 methodDisposeReleases all resources used by the current instance of the AsymmetricAlgorithm class. (Inherited from AsymmetricAlgorithm.)
Protected methodDispose(Boolean)Releases the unmanaged resources used by the AsymmetricAlgorithm class and optionally releases the managed resources. (Inherited from AsymmetricAlgorithm.)
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 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 a hash function for a particular type. (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 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

  NameDescription
Protected fieldKeySizeValueRepresents the size, in bits, of the key modulus used by the asymmetric algorithm. (Inherited from AsymmetricAlgorithm.)
Protected fieldLegalKeySizesValueSpecifies the key sizes that are supported by the asymmetric algorithm. (Inherited from AsymmetricAlgorithm.)
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.


Imports System
Imports System.IO
Imports System.Security.Cryptography
Imports System.Text

Class Alice

    Public Shared Sub Main(ByVal args() As String)
        Dim bob As New Bob()
        If (True) Then
            Using dsa As New ECDsaCng()
                    dsa.HashAlgorithm = CngAlgorithm.Sha256
                    bob.key = dsa.Key.Export(CngKeyBlobFormat.EccPublicBlob)
                    Dim data() As Byte = {21, 5, 8, 12, 207}
                    Dim signature As Byte() = dsa.SignData(data)
                    bob.Receive(data, signature)
            End Using
        End If

    End Sub 'Main
End Class 'Alice 


Public Class Bob
    Public key() As Byte

    Public Sub Receive(ByVal data() As Byte, ByVal signature() As Byte)
        Using ecsdKey As New ECDsaCng(CngKey.Import(key, CngKeyBlobFormat.EccPublicBlob))
                If ecsdKey.VerifyData(data, signature) Then
                    Console.WriteLine("Data is good")
                Else
                    Console.WriteLine("Data is bad")
                End If
        End Using

    End Sub 'Receive
End Class 'Bob 


.NET Framework

Supported in: 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later)

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.

Date

History

Reason

March 2011

Added example.

Information enhancement.

Community Additions

Show:
© 2017 Microsoft