Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class System.​Security.​Cryptography.​ECDiffieHellmanCng

Assembly: System.Security.Cryptography

Inheritance: object → AsymmetricAlgorithmECAlgorithmECDiffieHellman → ECDiffieHellmanCng

Implemented Interfaces

Provides a Cryptography Next Generation (CNG) implementation of the Elliptic Curve Diffie-Hellman (ECDH) algorithm. This class is used to perform cryptographic operations.

Fields and Constants

protected int
KeySizeValue
Represents the size, in bits, of the key modulus used by the asymmetric algorithm.
protected KeySizes[]
LegalKeySizesValue
Specifies the key sizes that are supported by the asymmetric algorithm.

Properties

public CngAlgorithm
HashAlgorithm
Gets or sets the hash algorithm to use when generating key material.
public byte[]
HmacKey
Gets or sets the Hash-based Message Authentication Code (HMAC) key to use when deriving key material.
public CngKey
Key
Specifies the <see cref="T:System.Security.Cryptography.CngKey" /> that is used by the current object for cryptographic operations.
KeyDerivationFunction
Gets or sets the key derivation function for the <see cref="T:System.Security.Cryptography.ECDiffieHellmanCng" /> class.
public int
KeySize
Gets or sets the size, in bits, of the key modulus used by the asymmetric algorithm.
public byte[]
Label
Gets or sets the label value that is used for key derivation.
public KeySizes[]
LegalKeySizes
Gets the key sizes that are supported by the asymmetric algorithm.
PublicKey
Gets the public key that can be used by another <see cref="T:System.Security.Cryptography.ECDiffieHellmanCng" /> object to generate a shared secret agreement.
public byte[]
SecretAppend
Gets or sets a value that will be appended to the secret agreement when generating key material.
public byte[]
SecretPrepend
Gets or sets a value that will be added to the beginning of the secret agreement when deriving key material.
public byte[]
Seed
Gets or sets the seed value that will be used when deriving key material.
public bool
UseSecretAgreementAsHmacKey
Gets a value that indicates whether the secret agreement is used as a Hash-based Message Authentication Code (HMAC) key to derive key material.
public string
KeyExchangeAlgorithm
Gets the name of the key exchange algorithm.
public string
SignatureAlgorithm
Gets the name of the signature algorithm.

Methods

public byte[]
DeriveKeyFromHash​(ECDiffieHellmanPublicKey otherPartyPublicKey, HashAlgorithmName hashAlgorithm, byte[] secretPrepend, byte[] secretAppend)
Performs key derivation using a specified hash algorithm with optional prepended or appended data.
Returns The hash of the shared secret after prepending or appending data as requested.
otherPartyPublicKey The other party's public key.
hashAlgorithm The hash algorithm to use to derive the key material.
secretPrepend A value to prepend to the derived secret before hashing.
secretAppend A value to append to the derived secret before hashing.
public byte[]
DeriveKeyFromHmac​(ECDiffieHellmanPublicKey otherPartyPublicKey, HashAlgorithmName hashAlgorithm, byte[] hmacKey, byte[] secretPrepend, byte[] secretAppend)
Performs key derivation using a specified HMAC (Hash-based Message Authentication Code) algorithm with optional prepended or appended data.
Returns The HMAC of the shared secret after prepending or appending data as requested.
otherPartyPublicKey The other party's public key.
hashAlgorithm The hash algorithm to use to derive the key material.
hmacKey The key for the HMAC.
secretPrepend A value to prepend to the derived secret before hashing.
secretAppend A value to append to the derived secret before hashing.
public byte[]
DeriveKeyMaterial​(CngKey otherPartyPublicKey)
Derives the key material that is generated from the secret agreement between two parties, given a <see cref="T:System.Security.Cryptography.CngKey" /> object that contains the second party's public key.
Returns A byte array that contains the key material. This information is generated from the secret agreement that is calculated from the current object's private key and the specified public key.
otherPartyPublicKey An object that contains the public part of the Elliptic Curve Diffie-Hellman (ECDH) key from the other party in the key exchange.
public byte[]
DeriveKeyMaterial​(ECDiffieHellmanPublicKey otherPartyPublicKey)
Derives the key material that is generated from the secret agreement between two parties, given an <see cref="T:System.Security.Cryptography.ECDiffieHellmanPublicKey" /> object that contains the second party's public key.
Returns A byte array that contains the key material. This information is generated from the secret agreement that is calculated from the current object's private key and the specified public key.
otherPartyPublicKey The public key from the other party in the key exchange.
public byte[]
DeriveKeyTls​(ECDiffieHellmanPublicKey otherPartyPublicKey, byte[] prfLabel, byte[] prfSeed)
Performs key derivation using the TLS (Transport Layer Security) 1.1 PRF (Pseudo-Random Function).
Returns The first 48 bytes from the TLS 1.1 PRF, using the shared secret as the key.
otherPartyPublicKey The other party's public key.
prfLabel The ASCII-encoded PRF label.
prfSeed The 64-byte PRF seed.
DeriveSecretAgreementHandle​(CngKey otherPartyPublicKey)
Gets a handle to the secret agreement generated between two parties, given a <see cref="T:System.Security.Cryptography.CngKey" /> object that contains the second party's public key.
Returns A handle to the secret agreement. This information is calculated from the current object's private key and the specified public key.
otherPartyPublicKey An object that contains the public part of the Elliptic Curve Diffie-Hellman (ECDH) key from the other party in the key exchange.
DeriveSecretAgreementHandle​(ECDiffieHellmanPublicKey otherPartyPublicKey)
Gets a handle to the secret agreement generated between two parties, given an <see cref="T:System.Security.Cryptography.ECDiffieHellmanPublicKey" /> object that contains the second party's public key.
Returns A handle to the secret agreement. This information is calculated from the current object's private key and the specified public key.
otherPartyPublicKey The public key from the other party in the key exchange.
protected void
Dispose​(bool disposing)
public byte[]
ExportEncryptedPkcs8PrivateKey​(ReadOnlySpan<​byte> passwordBytes, PbeParameters pbeParameters)
Exports the current key in the PKCS#8 EncryptedPrivateKeyInfo format with a byte-based password.
Returns A byte array containing the PKCS#8 EncryptedPrivateKeyInfo representation of this key.
passwordBytes The bytes to use as a password when encrypting the key material.
pbeParameters The password-based encryption (PBE) parameters to use when encrypting the key material.
public byte[]
ExportEncryptedPkcs8PrivateKey​(ReadOnlySpan<​char> password, PbeParameters pbeParameters)
Exports the current key in the PKCS#8 EncryptedPrivateKeyInfo format with a char-based password.
Returns A byte array containing the PKCS#8 EncryptedPrivateKeyInfo representation of this key.
password The password to use when encrypting the key material.
pbeParameters The password-based encryption (PBE) parameters to use when encrypting the key material.
public ECParameters
ExportExplicitParameters​(bool includePrivateParameters)
Exports the key and explicit curve parameters used by the <see cref="T:System.Security.Cryptography.ECCurve" /> object into an <see cref="T:System.Security.Cryptography.ECParameters" /> object.
Returns The key and explicit curve parameters used by the <see cref="T:System.Security.Cryptography.ECCurve" /> object.
includePrivateParameters <see langword="true" /> to include private parameters; otherwise, <see langword="false" /> .
public ECParameters
ExportParameters​(bool includePrivateParameters)
Exports the key used by the <see cref="T:System.Security.Cryptography.ECCurve" /> object into an <see cref="T:System.Security.Cryptography.ECParameters" /> object.
Returns The key and named curve parameters used by the <see cref="T:System.Security.Cryptography.ECCurve" /> object.
includePrivateParameters <see langword="true" /> to include private parameters; otherwise, <see langword="false" /> .
public void
FromXmlString​(string xml, ECKeyXmlFormat format)
Deserializes the key information from an XML string by using the specified format.
xml The XML-based key information to be deserialized.
format One of the enumeration values that specifies the format of the XML string. The only currently accepted format is <see cref="F:System.Security.Cryptography.ECKeyXmlFormat.Rfc4050" /> .
public void
GenerateKey​(ECCurve curve)
Generates a new ephemeral public/private key pair for the specified curve.
curve The curve used to generate an ephemeral public/private key pair.
public void
ImportEncryptedPkcs8PrivateKey​(ReadOnlySpan<​byte> passwordBytes, ReadOnlySpan<​byte> source, Int32& bytesRead)
public void
ImportEncryptedPkcs8PrivateKey​(ReadOnlySpan<​char> password, ReadOnlySpan<​byte> source, Int32& bytesRead)
public void
ImportParameters​(ECParameters parameters)
Imports the specified parameters for an <see cref="T:System.Security.Cryptography.ECCurve" /> object as a key into the current instance.
parameters The curve's parameters to import.
public void
ImportPkcs8PrivateKey​(ReadOnlySpan<​byte> source, Int32& bytesRead)
public string
ToXmlString​(ECKeyXmlFormat format)
Serializes the key information to an XML string by using the specified format.
Returns A string object that contains the key information, serialized to an XML string, according to the requested format.
format One of the enumeration values that specifies the format of the XML string. The only currently accepted format is <see cref="F:System.Security.Cryptography.ECKeyXmlFormat.Rfc4050" /> .
public bool
TryExportEncryptedPkcs8PrivateKey​(ReadOnlySpan<​byte> passwordBytes, PbeParameters pbeParameters, Span<​byte> destination, Int32& bytesWritten)
public bool
TryExportEncryptedPkcs8PrivateKey​(ReadOnlySpan<​char> password, PbeParameters pbeParameters, Span<​byte> destination, Int32& bytesWritten)
public bool
TryExportPkcs8PrivateKey​(Span<​byte> destination, Int32& bytesWritten)
public byte[]
DeriveKeyFromHash​(ECDiffieHellmanPublicKey otherPartyPublicKey, HashAlgorithmName hashAlgorithm)
Inherited from ECDiffieHellman
Performs key derivation using a specified hash algorithm.
Returns The hash of the shared secret.
otherPartyPublicKey The other party's public key.
hashAlgorithm The hash algorithm to use to derive the key material.
public byte[]
DeriveKeyFromHmac​(ECDiffieHellmanPublicKey otherPartyPublicKey, HashAlgorithmName hashAlgorithm, byte[] hmacKey)
Inherited from ECDiffieHellman
Performs key derivation using a specified HMAC (Hash-based Message Authentication Code) algorithm.
Returns The HMAC of the shared secret.
otherPartyPublicKey The other party's public key.
hashAlgorithm The hash algorithm to use to derive the key material.
hmacKey The key for the HMAC.
public byte[]
DeriveRawSecretAgreement​(ECDiffieHellmanPublicKey otherPartyPublicKey)
Inherited from ECDiffieHellman
Derive raw key material.
Returns The raw key agreement.
otherPartyPublicKey The public key of the party with which to derive a mutual secret.
public void
FromXmlString​(string xmlString)
Inherited from ECDiffieHellman
This method throws in all cases.
xmlString The XML string to use to reconstruct the <see cref="T:System.Security.Cryptography.AsymmetricAlgorithm" /> object.
public string
ToXmlString​(bool includePrivateParameters)
Inherited from ECDiffieHellman
This method throws in all cases.
Returns This method does not return a value.
includePrivateParameters <see langword="true" /> to include private parameters; otherwise, <see langword="false" /> .
public byte[]
ExportECPrivateKey​()
Inherited from ECAlgorithm
Exports the current key in the ECPrivateKey format.
Returns A byte array containing the ECPrivateKey representation of this key.
public string
ExportECPrivateKeyPem​()
Inherited from ECAlgorithm
Exports the current key in the ECPrivateKey format, PEM encoded.
Returns A string containing the PEM-encoded ECPrivateKey.
public void
ImportECPrivateKey​(ReadOnlySpan<​byte> source, Int32& bytesRead)
Inherited from ECAlgorithm
public void
ImportFromEncryptedPem​(ReadOnlySpan<​char> input, ReadOnlySpan<​byte> passwordBytes)
Inherited from ECAlgorithm
Imports an encrypted RFC 7468 PEM-encoded private key, replacing the keys for this object.
input The PEM text of the encrypted key to import.
passwordBytes The bytes to use as a password when decrypting the key material.
public void
ImportFromEncryptedPem​(ReadOnlySpan<​char> input, ReadOnlySpan<​char> password)
Inherited from ECAlgorithm
Imports an encrypted RFC 7468 PEM-encoded private key, replacing the keys for this object.
input The PEM text of the encrypted key to import.
password The password to use for decrypting the key material.
public void
ImportFromPem​(ReadOnlySpan<​char> input)
Inherited from ECAlgorithm
Imports an RFC 7468 PEM-encoded key, replacing the keys for this object.
input The PEM text of the key to import.
public void
ImportSubjectPublicKeyInfo​(ReadOnlySpan<​byte> source, Int32& bytesRead)
Inherited from ECAlgorithm
public bool
TryExportECPrivateKey​(Span<​byte> destination, Int32& bytesWritten)
Inherited from ECAlgorithm
public bool
TryExportECPrivateKeyPem​(Span<​char> destination, Int32& charsWritten)
Inherited from ECAlgorithm
public bool
TryExportSubjectPublicKeyInfo​(Span<​byte> destination, Int32& bytesWritten)
Inherited from ECAlgorithm
public void
Clear​()
Inherited from AsymmetricAlgorithm
Releases all resources used by the <see cref="T:System.Security.Cryptography.AsymmetricAlgorithm" /> class.
public void
Dispose​()
Inherited from AsymmetricAlgorithm
Releases all resources used by the current instance of the <see cref="T:System.Security.Cryptography.AsymmetricAlgorithm" /> class.
public string
ExportEncryptedPkcs8PrivateKeyPem​(ReadOnlySpan<​byte> passwordBytes, PbeParameters pbeParameters)
Inherited from AsymmetricAlgorithm
Exports the current key in the PKCS#8 EncryptedPrivateKeyInfo format with a byte-based password, PEM encoded.
Returns A string containing the PEM-encoded PKCS#8 EncryptedPrivateKeyInfo.
passwordBytes The bytes to use as a password when encrypting the key material.
pbeParameters The password-based encryption (PBE) parameters to use when encrypting the key material.
public string
ExportEncryptedPkcs8PrivateKeyPem​(ReadOnlySpan<​char> password, PbeParameters pbeParameters)
Inherited from AsymmetricAlgorithm
Exports the current key in the PKCS#8 EncryptedPrivateKeyInfo format with a char-based password, PEM encoded.
Returns A string containing the PEM-encoded PKCS#8 EncryptedPrivateKeyInfo.
password The password to use when encrypting the key material.
pbeParameters The password-based encryption (PBE) parameters to use when encrypting the key material.
public byte[]
ExportPkcs8PrivateKey​()
Inherited from AsymmetricAlgorithm
Exports the current key in the PKCS#8 PrivateKeyInfo format.
Returns A byte array containing the PKCS#8 PrivateKeyInfo representation of this key.
public string
ExportPkcs8PrivateKeyPem​()
Inherited from AsymmetricAlgorithm
Exports the current key in the PKCS#8 PrivateKeyInfo format, PEM encoded.
Returns A string containing the PEM-encoded PKCS#8 PrivateKeyInfo.
public byte[]
ExportSubjectPublicKeyInfo​()
Inherited from AsymmetricAlgorithm
Exports the public-key portion of the current key in the X.509 SubjectPublicKeyInfo format.
Returns A byte array containing the X.509 SubjectPublicKeyInfo representation of the public-key portion of this key.
public string
ExportSubjectPublicKeyInfoPem​()
Inherited from AsymmetricAlgorithm
Exports the public-key portion of the current key in the X.509 SubjectPublicKeyInfo format, PEM encoded.
Returns A string containing the PEM-encoded X.509 SubjectPublicKeyInfo.
public bool
TryExportEncryptedPkcs8PrivateKeyPem​(ReadOnlySpan<​byte> passwordBytes, PbeParameters pbeParameters, Span<​char> destination, Int32& charsWritten)
Inherited from AsymmetricAlgorithm
public bool
TryExportEncryptedPkcs8PrivateKeyPem​(ReadOnlySpan<​char> password, PbeParameters pbeParameters, Span<​char> destination, Int32& charsWritten)
Inherited from AsymmetricAlgorithm
public bool
TryExportPkcs8PrivateKeyPem​(Span<​char> destination, Int32& charsWritten)
Inherited from AsymmetricAlgorithm
public bool
TryExportSubjectPublicKeyInfoPem​(Span<​char> destination, Int32& charsWritten)
Inherited from AsymmetricAlgorithm
public bool
Equals​(object obj)
Inherited from object
protected void
Finalize​()
Inherited from object
public int
GetHashCode​()
Inherited from object
public Type
GetType​()
Inherited from object
protected object
MemberwiseClone​()
Inherited from object
public string
ToString​()
Inherited from object