ECDiffieHellmanCng ECDiffieHellmanCng ECDiffieHellmanCng ECDiffieHellmanCng Class

定义

提供椭圆曲线 Diffie-Hellman (ECDH) 算法的下一代加密技术 (CNG) 实现。Provides a Cryptography Next Generation (CNG) implementation of the Elliptic Curve Diffie-Hellman (ECDH) algorithm. 此类用于执行加密操作。This class is used to perform cryptographic operations.

public ref class ECDiffieHellmanCng sealed : System::Security::Cryptography::ECDiffieHellman
public sealed class ECDiffieHellmanCng : System.Security.Cryptography.ECDiffieHellman
type ECDiffieHellmanCng = class
    inherit ECDiffieHellman
Public NotInheritable Class ECDiffieHellmanCng
Inherits ECDiffieHellman
继承

示例

下面的示例演示如何使用ECDiffieHellmanCng类建立密钥交换, 以及如何使用该密钥对可以通过公共通道发送并由接收方解密的消息进行加密。The following example shows how to use the ECDiffieHellmanCng class to establish a key exchange and how to use that key to encrypt a message that can be sent over a public channel and decrypted by the receiver.

using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;


class Alice
{
    public static byte[] alicePublicKey;

    public static void Main(string[] args)
    {
        using (ECDiffieHellmanCng alice = new ECDiffieHellmanCng())
        {

            alice.KeyDerivationFunction = ECDiffieHellmanKeyDerivationFunction.Hash;
            alice.HashAlgorithm = CngAlgorithm.Sha256;
            alicePublicKey = alice.PublicKey.ToByteArray();
            Bob bob = new Bob();
            CngKey k = CngKey.Import(bob.bobPublicKey, CngKeyBlobFormat.EccPublicBlob);
            byte[] aliceKey = alice.DeriveKeyMaterial(CngKey.Import(bob.bobPublicKey, CngKeyBlobFormat.EccPublicBlob));
            byte[] encryptedMessage = null;
            byte[] iv = null;
            Send(aliceKey, "Secret message", out encryptedMessage, out iv);
            bob.Receive(encryptedMessage, iv);
        }

    }

    private static void Send(byte[] key, string secretMessage, out byte[] encryptedMessage, out byte[] iv)
    {
        using (Aes aes = new AesCryptoServiceProvider())
        {
            aes.Key = key;
            iv = aes.IV;

            // Encrypt the message
            using (MemoryStream ciphertext = new MemoryStream())
            using (CryptoStream cs = new CryptoStream(ciphertext, aes.CreateEncryptor(), CryptoStreamMode.Write))
            {
                byte[] plaintextMessage = Encoding.UTF8.GetBytes(secretMessage);
                cs.Write(plaintextMessage, 0, plaintextMessage.Length);
                cs.Close();
                encryptedMessage = ciphertext.ToArray();
            }
        }
    }

}
public class Bob 
{
    public byte[] bobPublicKey;
    private byte[] bobKey;
    public Bob()
    {
        using (ECDiffieHellmanCng bob = new ECDiffieHellmanCng())
        {

            bob.KeyDerivationFunction = ECDiffieHellmanKeyDerivationFunction.Hash;
            bob.HashAlgorithm = CngAlgorithm.Sha256;
            bobPublicKey = bob.PublicKey.ToByteArray();
            bobKey = bob.DeriveKeyMaterial(CngKey.Import(Alice.alicePublicKey, CngKeyBlobFormat.EccPublicBlob));

        }
    }

    public void Receive(byte[] encryptedMessage, byte[] iv)
    {

        using (Aes aes = new AesCryptoServiceProvider())
        {
            aes.Key = bobKey;
            aes.IV = iv;
            // Decrypt the message
            using (MemoryStream plaintext = new MemoryStream())
            {
                using (CryptoStream cs = new CryptoStream(plaintext, aes.CreateDecryptor(), CryptoStreamMode.Write))
                {
                    cs.Write(encryptedMessage, 0, encryptedMessage.Length);
                    cs.Close();
                    string message = Encoding.UTF8.GetString(plaintext.ToArray());
                    Console.WriteLine(message);
                }
            }
        }
    }

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




Class Alice
    Public Shared alicePublicKey() As Byte


    Public Shared Sub Main(ByVal args() As String)
        Using alice As New ECDiffieHellmanCng()
            alice.KeyDerivationFunction = ECDiffieHellmanKeyDerivationFunction.Hash
            alice.HashAlgorithm = CngAlgorithm.Sha256
            alicePublicKey = alice.PublicKey.ToByteArray()
            Dim bob As New Bob()
            Dim k As CngKey = CngKey.Import(bob.bobPublicKey, CngKeyBlobFormat.EccPublicBlob)
            Dim aliceKey As Byte() = alice.DeriveKeyMaterial(CngKey.Import(bob.bobPublicKey, CngKeyBlobFormat.EccPublicBlob))
            Dim encryptedMessage As Byte() = Nothing
            Dim iv As Byte() = Nothing
            Send(aliceKey, "Secret message", encryptedMessage, iv)
            bob.Receive(encryptedMessage, iv)
        End Using
    End Sub


    Private Shared Sub Send(ByVal key() As Byte, ByVal secretMessage As String, ByRef encryptedMessage() As Byte, ByRef iv() As Byte)
        Using aes As New AesCryptoServiceProvider()
            aes.Key = key
            iv = aes.IV

            ' Encrypt the message
            Using ciphertext As New MemoryStream()
                Using cs As New CryptoStream(ciphertext, aes.CreateEncryptor(), CryptoStreamMode.Write)
                    Dim plaintextMessage As Byte() = Encoding.UTF8.GetBytes(secretMessage)
                    cs.Write(plaintextMessage, 0, plaintextMessage.Length)
                    cs.Close()
                    encryptedMessage = ciphertext.ToArray()
                End Using
            End Using
        End Using

    End Sub
End Class

Public Class Bob
    Public bobPublicKey() As Byte
    Private bobKey() As Byte

    Public Sub New()
        Using bob As New ECDiffieHellmanCng()

            bob.KeyDerivationFunction = ECDiffieHellmanKeyDerivationFunction.Hash
            bob.HashAlgorithm = CngAlgorithm.Sha256
            bobPublicKey = bob.PublicKey.ToByteArray()
            bobKey = bob.DeriveKeyMaterial(CngKey.Import(Alice.alicePublicKey, CngKeyBlobFormat.EccPublicBlob))
        End Using

    End Sub


    Public Sub Receive(ByVal encryptedMessage() As Byte, ByVal iv() As Byte)

        Using aes As New AesCryptoServiceProvider()
                aes.Key = bobKey
                aes.IV = iv
                ' Decrypt the message
            Using plaintext As New MemoryStream()
                Using cs As New CryptoStream(plaintext, aes.CreateDecryptor(), CryptoStreamMode.Write)
                    cs.Write(encryptedMessage, 0, encryptedMessage.Length)
                    cs.Close()
                    Dim message As String = Encoding.UTF8.GetString(plaintext.ToArray())
                    Console.WriteLine(message)
                End Using
            End Using
        End Using
    End Sub
End Class

注解

ECDiffieHellmanCng类允许两方交换私钥材料, 即使它们是通过公共通道进行通信。The ECDiffieHellmanCng class enables two parties to exchange private key material even if they are communicating through a public channel. 双方可以计算相同的机密值, 这在托管的 Diffie-hellman 类中称为机密协议Both parties can calculate the same secret value, which is referred to as the secret agreement in the managed Diffie-Hellman classes. 机密协议随后可用于多种用途, 包括对称密钥。The secret agreement can then be used for a variety of purposes, including as a symmetric key. 但是, ECDiffieHellmanCng类不直接公开机密协议, 而是在提供值之前对协议执行一些后期处理。However, instead of exposing the secret agreement directly, the ECDiffieHellmanCng class does some post-processing on the agreement before providing the value. 此 post 处理称为密钥派生函数 (KDF);您可以选择要使用的 KDF, 并通过 Diffie-hellman 对象实例上的一组属性设置其参数。This post processing is referred to as the key derivation function (KDF); you can select which KDF you want to use and set its parameters through a set of properties on the instance of the Diffie-Hellman object.

密钥派生函数Key derivation function 属性Properties
Hash HashAlgorithm-用于处理机密协议的哈希算法。HashAlgorithm - The hash algorithm that is used to process the secret agreement.

SecretPrepend-在对机密协议进行哈希处理之前, 要在其中追加到机密协议的可选字节数组。SecretPrepend - An optional byte array to prepend to the secret agreement before hashing it.

SecretAppend-要在哈希处理之前追加到机密协议的可选字节数组。SecretAppend - An optional byte array to append to the secret agreement before hashing it.
Hmac HashAlgorithm-用于处理机密协议的哈希算法。HashAlgorithm - The hash algorithm that is used to process the secret agreement.

SecretPrepend-在对机密协议进行哈希处理之前, 要在其中追加到机密协议的可选字节数组。SecretPrepend- An optional byte array to prepend to the secret agreement before hashing it.

SecretAppend-要在哈希处理之前追加到机密协议的可选字节数组。SecretAppend - An optional byte array to append to the secret agreement before hashing it.
Tls Label-密钥派生的标签。Label - The label for key derivation.

Seed-密钥派生的种子。Seed - The seed for key derivation.

通过密钥派生函数传递机密协议的结果是可用作应用程序密钥材料的字节数组。The result of passing the secret agreement through the key derivation function is a byte array that may be used as key material for your application. 生成的密钥材料的字节数取决于密钥派生函数;例如, SHA-256 将生成256位的密钥材料, 而 SHA-512 将生成512位的密钥材料。ECDH 密钥交换的基本流程如下所示:The number of bytes of key material generated is dependent on the key derivation function; for example, SHA-256 will generate 256 bits of key material, whereas SHA-512 will generate 512 bits of key material.The basic flow of an ECDH key exchange is as follows:

  1. Alice 和 Bob 创建用于 Diffie-hellman 密钥交换操作的密钥对Alice and Bob create a key pair to use for the Diffie-Hellman key exchange operation

  2. Alice 和 Bob 使用同意的参数配置 KDF。Alice and Bob configure the KDF using parameters the agree on.

  3. Alice 向 Bob 发送她的公钥。Alice sends Bob her public key.

  4. Bob 向 Alice 发送其公钥。Bob sends Alice his public key.

  5. Alice 和 Bob 使用彼此的公钥生成机密协议, 并将 KDF 应用到机密协议以生成密钥材料。Alice and Bob use each other's public keys to generate the secret agreement, and apply the KDF to the secret agreement to generate key material.

构造函数

ECDiffieHellmanCng() ECDiffieHellmanCng() ECDiffieHellmanCng() ECDiffieHellmanCng()

使用随机的密钥对初始化 ECDiffieHellmanCng 类的新实例。Initializes a new instance of the ECDiffieHellmanCng class with a random key pair.

ECDiffieHellmanCng(CngKey) ECDiffieHellmanCng(CngKey) ECDiffieHellmanCng(CngKey) ECDiffieHellmanCng(CngKey)

使用指定的 CngKey 对象初始化 ECDiffieHellmanCng 类的新实例。Initializes a new instance of the ECDiffieHellmanCng class by using the specified CngKey object.

ECDiffieHellmanCng(ECCurve) ECDiffieHellmanCng(ECCurve) ECDiffieHellmanCng(ECCurve) ECDiffieHellmanCng(ECCurve)

创建 ECDiffieHellmanCng 类的新实例,其公钥/私钥对通过指定曲线生成。Creates a new instance of the ECDiffieHellmanCng class whose public/private key pair is generated over the specified curve.

ECDiffieHellmanCng(Int32) ECDiffieHellmanCng(Int32) ECDiffieHellmanCng(Int32) ECDiffieHellmanCng(Int32)

使用指定密钥大小,通过随机密钥对来初始化 ECDiffieHellmanCng 类的新实例。Initializes a new instance of the ECDiffieHellmanCng class with a random key pair, using the specified key size.

属性

HashAlgorithm HashAlgorithm HashAlgorithm HashAlgorithm

获取或设置生成密钥材料时要使用的哈希算法。Gets or sets the hash algorithm to use when generating key material.

HmacKey HmacKey HmacKey HmacKey

获取或设置派生密钥材料时要使用的基于哈希的消息身份验证代码 (HMAC) 密钥。Gets or sets the Hash-based Message Authentication Code (HMAC) key to use when deriving key material.

Key Key Key Key

指定当前对象用于加密操作的 CngKeySpecifies the CngKey that is used by the current object for cryptographic operations.

KeyDerivationFunction KeyDerivationFunction KeyDerivationFunction KeyDerivationFunction

获取或设置 ECDiffieHellmanCng 类的密钥派生函数。Gets or sets the key derivation function for the ECDiffieHellmanCng class.

KeyExchangeAlgorithm KeyExchangeAlgorithm KeyExchangeAlgorithm KeyExchangeAlgorithm

获取密钥交换算法的名称。Gets the name of the key exchange algorithm.

(Inherited from ECDiffieHellman)
KeySize KeySize KeySize KeySize
Label Label Label Label

获取或设置用于密钥派生的标签值。Gets or sets the label value that is used for key derivation.

LegalKeySizes LegalKeySizes LegalKeySizes LegalKeySizes
PublicKey PublicKey PublicKey PublicKey

获取另一个 ECDiffieHellmanCng 对象可用来生成共享机密协议的公钥。Gets the public key that can be used by another ECDiffieHellmanCng object to generate a shared secret agreement.

SecretAppend SecretAppend SecretAppend SecretAppend

获取或设置生成密钥材料时将追加到机密协议的值。Gets or sets a value that will be appended to the secret agreement when generating key material.

SecretPrepend SecretPrepend SecretPrepend SecretPrepend

获取或设置派生密钥材料时将添加到机密协议开头的值。Gets or sets a value that will be added to the beginning of the secret agreement when deriving key material.

Seed Seed Seed Seed

获取或设置派生密钥材料时将要使用的种子值。Gets or sets the seed value that will be used when deriving key material.

SignatureAlgorithm SignatureAlgorithm SignatureAlgorithm SignatureAlgorithm

获取签名算法的名称。Gets the name of the signature algorithm.

(Inherited from ECDiffieHellman)
UseSecretAgreementAsHmacKey UseSecretAgreementAsHmacKey UseSecretAgreementAsHmacKey UseSecretAgreementAsHmacKey

获取一个值,该值指示机密协议是否用作基于哈希的消息身份验证代码 (HMAC) 密钥以派生密钥材料。Gets a value that indicates whether the secret agreement is used as a Hash-based Message Authentication Code (HMAC) key to derive key material.

方法

Clear() Clear() Clear() Clear()

释放 AsymmetricAlgorithm 类使用的所有资源。Releases all resources used by the AsymmetricAlgorithm class.

(Inherited from AsymmetricAlgorithm)
DeriveKeyFromHash(ECDiffieHellmanPublicKey, HashAlgorithmName) DeriveKeyFromHash(ECDiffieHellmanPublicKey, HashAlgorithmName) DeriveKeyFromHash(ECDiffieHellmanPublicKey, HashAlgorithmName) DeriveKeyFromHash(ECDiffieHellmanPublicKey, HashAlgorithmName)

若给定了另一方的公钥和哈希算法的名称,使用哈希函数派生可用作密钥的字节。Derives bytes that can be used as a key using a hash function, given another party's public key and hash algorithm's name.

(Inherited from ECDiffieHellman)
DeriveKeyFromHash(ECDiffieHellmanPublicKey, HashAlgorithmName, Byte[], Byte[]) DeriveKeyFromHash(ECDiffieHellmanPublicKey, HashAlgorithmName, Byte[], Byte[]) DeriveKeyFromHash(ECDiffieHellmanPublicKey, HashAlgorithmName, Byte[], Byte[]) DeriveKeyFromHash(ECDiffieHellmanPublicKey, HashAlgorithmName, Byte[], Byte[])

若给定了另一方的公钥、哈希算法的名称、预置值和追加值,使用哈希函数派生可用作密钥的字节。Derives bytes that can be used as a key using a hash function, given another party's public key, hash algorithm's name, a prepend value and an append value.

DeriveKeyFromHmac(ECDiffieHellmanPublicKey, HashAlgorithmName, Byte[]) DeriveKeyFromHmac(ECDiffieHellmanPublicKey, HashAlgorithmName, Byte[]) DeriveKeyFromHmac(ECDiffieHellmanPublicKey, HashAlgorithmName, Byte[]) DeriveKeyFromHmac(ECDiffieHellmanPublicKey, HashAlgorithmName, Byte[])

使用基于哈希的消息验证代码 (HMAC) 派生可用作密钥的字节。Derives bytes that can be used as a key using a Hash-based Message Authentication Code (HMAC).

(Inherited from ECDiffieHellman)
DeriveKeyFromHmac(ECDiffieHellmanPublicKey, HashAlgorithmName, Byte[], Byte[], Byte[]) DeriveKeyFromHmac(ECDiffieHellmanPublicKey, HashAlgorithmName, Byte[], Byte[], Byte[]) DeriveKeyFromHmac(ECDiffieHellmanPublicKey, HashAlgorithmName, Byte[], Byte[], Byte[]) DeriveKeyFromHmac(ECDiffieHellmanPublicKey, HashAlgorithmName, Byte[], Byte[], Byte[])

使用基于哈希的消息验证代码 (HMAC) 派生可用作密钥的字节。Derives bytes that can be used as a key using a Hash-based Message Authentication Code (HMAC).

DeriveKeyMaterial(CngKey) DeriveKeyMaterial(CngKey) DeriveKeyMaterial(CngKey) DeriveKeyMaterial(CngKey)

在给定包含第二方公钥的 CngKey 对象的情况下,派生从双方之间的机密协议生成的密钥材料。Derives the key material that is generated from the secret agreement between two parties, given a CngKey object that contains the second party's public key.

DeriveKeyMaterial(ECDiffieHellmanPublicKey) DeriveKeyMaterial(ECDiffieHellmanPublicKey) DeriveKeyMaterial(ECDiffieHellmanPublicKey) DeriveKeyMaterial(ECDiffieHellmanPublicKey)

在给定包含第二方公钥的 ECDiffieHellmanPublicKey 对象的情况下,派生从双方之间的机密协议生成的密钥材料。Derives the key material that is generated from the secret agreement between two parties, given an ECDiffieHellmanPublicKey object that contains the second party's public key.

DeriveKeyTls(ECDiffieHellmanPublicKey, Byte[], Byte[]) DeriveKeyTls(ECDiffieHellmanPublicKey, Byte[], Byte[]) DeriveKeyTls(ECDiffieHellmanPublicKey, Byte[], Byte[]) DeriveKeyTls(ECDiffieHellmanPublicKey, Byte[], Byte[])

使用传输层安全性 (TLS) 伪随机功能 (PRF) 派生算法派生可用作密钥的字节。Derives bytes that can be used as a key using a Transport Layer Security (TLS) Pseudo-Random Function (PRF) derivation algorithm.

DeriveSecretAgreementHandle(CngKey) DeriveSecretAgreementHandle(CngKey) DeriveSecretAgreementHandle(CngKey) DeriveSecretAgreementHandle(CngKey)

在给定包含另一方公钥的 CngKey 对象的情况下,获取双方之间生成的机密协议的句柄。Gets a handle to the secret agreement generated between two parties, given a CngKey object that contains the second party's public key.

DeriveSecretAgreementHandle(ECDiffieHellmanPublicKey) DeriveSecretAgreementHandle(ECDiffieHellmanPublicKey) DeriveSecretAgreementHandle(ECDiffieHellmanPublicKey) DeriveSecretAgreementHandle(ECDiffieHellmanPublicKey)

在给定包含另一方公钥的 ECDiffieHellmanPublicKey 对象的情况下,获取双方之间生成的机密协议的句柄。Gets a handle to the secret agreement generated between two parties, given an ECDiffieHellmanPublicKey object that contains the second party's public key.

Dispose() Dispose() Dispose() Dispose()

释放 AsymmetricAlgorithm 类的当前实例所使用的所有资源。Releases all resources used by the current instance of the AsymmetricAlgorithm class.

(Inherited from AsymmetricAlgorithm)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

释放 AsymmetricAlgorithm 类使用的非托管资源,并可以选择释放托管资源。Releases the unmanaged resources used by the AsymmetricAlgorithm class and optionally releases the managed resources.

(Inherited from AsymmetricAlgorithm)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
ExportECPrivateKey() ExportECPrivateKey() ExportECPrivateKey() ExportECPrivateKey()

以 ECPrivateKey 格式导出当前密钥。Exports the current key in the ECPrivateKey format.

(Inherited from ECDiffieHellman)
ExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Byte>, PbeParameters) ExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Byte>, PbeParameters) ExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Byte>, PbeParameters) ExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Byte>, PbeParameters)

使用基于字节的密码以 PKCS#8 EncryptedPrivateKeyInfo 格式导出当前密钥。Exports the current key in the PKCS#8 EncryptedPrivateKeyInfo format with a byte-based password.

(Inherited from AsymmetricAlgorithm)
ExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Char>, PbeParameters) ExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Char>, PbeParameters) ExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Char>, PbeParameters) ExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Char>, PbeParameters)

使用基于字符的密码以 PKCS#8 EncryptedPrivateKeyInfo 格式导出当前密钥。Exports the current key in the PKCS#8 EncryptedPrivateKeyInfo format with a char-based password.

(Inherited from AsymmetricAlgorithm)
ExportExplicitParameters(Boolean) ExportExplicitParameters(Boolean) ExportExplicitParameters(Boolean) ExportExplicitParameters(Boolean)

ECCurve 对象使用的密钥和显式曲线参数导出到 ECParameters 对象。Exports the key and explicit curve parameters used by the ECCurve object into an ECParameters object.

ExportParameters(Boolean) ExportParameters(Boolean) ExportParameters(Boolean) ExportParameters(Boolean)

ECCurve 对象使用的密钥导出到 ECParameters 对象。Exports the key used by the ECCurve object into an ECParameters object.

ExportPkcs8PrivateKey() ExportPkcs8PrivateKey() ExportPkcs8PrivateKey() ExportPkcs8PrivateKey()

以 PKCS#8 PrivateKeyInfo 格式导出当前密钥。Exports the current key in the PKCS#8 PrivateKeyInfo format.

(Inherited from AsymmetricAlgorithm)
ExportSubjectPublicKeyInfo() ExportSubjectPublicKeyInfo() ExportSubjectPublicKeyInfo() ExportSubjectPublicKeyInfo()

以 X.509 SubjectPublicKeyInfo 格式导出当前密钥的公钥部分。Exports the public-key portion of the current key in the X.509 SubjectPublicKeyInfo format.

(Inherited from AsymmetricAlgorithm)
FromXmlString(String) FromXmlString(String) FromXmlString(String) FromXmlString(String)

未实现此方法。This method is not implemented.

FromXmlString(String, ECKeyXmlFormat) FromXmlString(String, ECKeyXmlFormat) FromXmlString(String, ECKeyXmlFormat) FromXmlString(String, ECKeyXmlFormat)

使用指定的格式反序列化 XML 字符串中的密钥信息。Deserializes the key information from an XML string by using the specified format.

GenerateKey(ECCurve) GenerateKey(ECCurve) GenerateKey(ECCurve) GenerateKey(ECCurve)

为指定曲线生成新的临时公钥/私钥对。Generates a new ephemeral public/private key pair for the specified curve.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
ImportECPrivateKey(ReadOnlySpan<Byte>, Int32) ImportECPrivateKey(ReadOnlySpan<Byte>, Int32) ImportECPrivateKey(ReadOnlySpan<Byte>, Int32) ImportECPrivateKey(ReadOnlySpan<Byte>, Int32)

从 ECPrivateKey 结构中导入公共/私有密钥对,替换此对象的密钥。Imports the public/private keypair from an ECPrivateKey structure, replacing the keys for this object.

(Inherited from ECDiffieHellman)
ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, Int32) ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, Int32) ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, Int32) ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<Byte>, ReadOnlySpan<Byte>, Int32)

使用基于字节的密码解密之后,从 PKCS#8 EncryptedPrivateKeyInfo 结构中导入公/私钥对,以替换此对象的密钥。Imports the public/private keypair from a PKCS#8 EncryptedPrivateKeyInfo structure after decrypting with a byte-based password, replacing the keys for this object.

(Inherited from ECDiffieHellman)
ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<Char>, ReadOnlySpan<Byte>, Int32) ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<Char>, ReadOnlySpan<Byte>, Int32) ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<Char>, ReadOnlySpan<Byte>, Int32) ImportEncryptedPkcs8PrivateKey(ReadOnlySpan<Char>, ReadOnlySpan<Byte>, Int32)

使用基于字符的密码解密之后,从 PKCS#8 EncryptedPrivateKeyInfo 结构中导入公/私钥对,以替换此对象的密钥。Imports the public/private keypair from a PKCS#8 EncryptedPrivateKeyInfo structure after decrypting with a char-based password, replacing the keys for this object.

(Inherited from ECDiffieHellman)
ImportParameters(ECParameters) ImportParameters(ECParameters) ImportParameters(ECParameters) ImportParameters(ECParameters)

ECCurve 对象的指定参数作为密钥导入当前实例。Imports the specified parameters for an ECCurve object as a key into the current instance.

ImportPkcs8PrivateKey(ReadOnlySpan<Byte>, Int32) ImportPkcs8PrivateKey(ReadOnlySpan<Byte>, Int32) ImportPkcs8PrivateKey(ReadOnlySpan<Byte>, Int32) ImportPkcs8PrivateKey(ReadOnlySpan<Byte>, Int32)

解密后,从 PKCS#8 PrivateKeyInfo 结构中导入公/私钥对,以替换此对象的密钥。Imports the public/private keypair from a PKCS#8 PrivateKeyInfo structure after decryption, replacing the keys for this object.

(Inherited from ECDiffieHellman)
ImportSubjectPublicKeyInfo(ReadOnlySpan<Byte>, Int32) ImportSubjectPublicKeyInfo(ReadOnlySpan<Byte>, Int32) ImportSubjectPublicKeyInfo(ReadOnlySpan<Byte>, Int32) ImportSubjectPublicKeyInfo(ReadOnlySpan<Byte>, Int32)

解密后,从 X.509 SubjectPublicKeyInfo 结构中导入公钥,以替换此对象的密钥。Imports the public key from an X.509 SubjectPublicKeyInfo structure after decryption, replacing the keys for this object.

(Inherited from ECDiffieHellman)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)
ToXmlString(Boolean) ToXmlString(Boolean) ToXmlString(Boolean) ToXmlString(Boolean)

未实现此方法。This method is not implemented.

ToXmlString(ECKeyXmlFormat) ToXmlString(ECKeyXmlFormat) ToXmlString(ECKeyXmlFormat) ToXmlString(ECKeyXmlFormat)

使用指定的格式将密钥信息序列化为 XML 字符串。Serializes the key information to an XML string by using the specified format.

TryExportECPrivateKey(Span<Byte>, Int32) TryExportECPrivateKey(Span<Byte>, Int32) TryExportECPrivateKey(Span<Byte>, Int32) TryExportECPrivateKey(Span<Byte>, Int32)

尝试以 ECPrivateKey 格式将当前密钥导入所提供的缓冲区。Attempts to export the current key in the ECPrivateKey format into a provided buffer.

(Inherited from ECDiffieHellman)
TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Byte>, PbeParameters, Span<Byte>, Int32) TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Byte>, PbeParameters, Span<Byte>, Int32) TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Byte>, PbeParameters, Span<Byte>, Int32) TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Byte>, PbeParameters, Span<Byte>, Int32)

尝试使用基于字节的密码以 PKCS#8 EncryptedPrivateKeyInfo 格式将当前密钥导出到所提供的缓冲区。Attempts to export the current key in the PKCS#8 EncryptedPrivateKeyInfo format into a provided buffer, using a byte-based password.

(Inherited from ECDiffieHellman)
TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Char>, PbeParameters, Span<Byte>, Int32) TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Char>, PbeParameters, Span<Byte>, Int32) TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Char>, PbeParameters, Span<Byte>, Int32) TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan<Char>, PbeParameters, Span<Byte>, Int32)

尝试使用基于字符的密码以 PKCS#8 EncryptedPrivateKeyInfo 格式将当前密钥导入所提供的缓冲区。Attempts to export the current key in the PKCS#8 EncryptedPrivateKeyInfo format into a provided buffer, using a char-based password.

(Inherited from ECDiffieHellman)
TryExportPkcs8PrivateKey(Span<Byte>, Int32) TryExportPkcs8PrivateKey(Span<Byte>, Int32) TryExportPkcs8PrivateKey(Span<Byte>, Int32) TryExportPkcs8PrivateKey(Span<Byte>, Int32)

尝试以 PKCS#8 PrivateKeyInfo 格式将当前密钥导出到所提供的缓冲区。Attempts to export the current key in the PKCS#8 PrivateKeyInfo format into a provided buffer.

(Inherited from ECDiffieHellman)
TryExportSubjectPublicKeyInfo(Span<Byte>, Int32) TryExportSubjectPublicKeyInfo(Span<Byte>, Int32) TryExportSubjectPublicKeyInfo(Span<Byte>, Int32) TryExportSubjectPublicKeyInfo(Span<Byte>, Int32)

尝试以 X.509 SubjectPublicKeyInfo 格式将当前密钥导出到所提供的缓冲区。Attempts to export the current key in the X.509 SubjectPublicKeyInfo format into a provided buffer.

(Inherited from ECDiffieHellman)

字段

KeySizeValue KeySizeValue KeySizeValue KeySizeValue

表示非对称算法所用密钥模块的大小(以位为单位)。Represents the size, in bits, of the key modulus used by the asymmetric algorithm.

(Inherited from AsymmetricAlgorithm)
LegalKeySizesValue LegalKeySizesValue LegalKeySizesValue LegalKeySizesValue

指定非对称算法支持的密钥大小。Specifies the key sizes that are supported by the asymmetric algorithm.

(Inherited from AsymmetricAlgorithm)

显式界面实现

IDisposable.Dispose() IDisposable.Dispose() IDisposable.Dispose() IDisposable.Dispose()

有关此成员的说明,请参见 Dispose()For a description of this member, see Dispose().

(Inherited from AsymmetricAlgorithm)

适用于