AsymmetricKeyExchangeDeformatter 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
代表所有非對稱金鑰交換格式化器的基底類別。
public ref class AsymmetricKeyExchangeDeformatter abstract
public abstract class AsymmetricKeyExchangeDeformatter
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public abstract class AsymmetricKeyExchangeDeformatter
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class AsymmetricKeyExchangeDeformatter
type AsymmetricKeyExchangeDeformatter = class
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
type AsymmetricKeyExchangeDeformatter = class
[<System.Runtime.InteropServices.ComVisible(true)>]
type AsymmetricKeyExchangeDeformatter = class
Public MustInherit Class AsymmetricKeyExchangeDeformatter
- 繼承
-
AsymmetricKeyExchangeDeformatter
- 衍生
- 屬性
範例
以下範例示範如何擴展該 AsymmetricKeyExchangeDeformatter 類別。
using System;
using System.Security.Cryptography;
namespace Contoso
{
public class ContosoDeformatter : AsymmetricKeyExchangeDeformatter
{
private RSA _rsaKey;
// Default constructor.
public ContosoDeformatter() { }
// Constructor with the public key to use for encryption.
public ContosoDeformatter(AsymmetricAlgorithm key)
{
SetKey(key);
}
// Set the public key for encyption operations.
public override void SetKey(AsymmetricAlgorithm key)
{
if (key != null)
{
_rsaKey = (RSA)key;
}
else
{
throw new ArgumentNullException(nameof(key));
}
}
// Disallow access to the parameters of the formatter.
public override string Parameters
{
get { return null; }
set {; }
}
// Create the encrypted key exchange data from the specified input
// data. This method uses the RSA class only. To
// support additional providers or provide custom decryption logic,
// add logic to this member.
public override byte[] DecryptKeyExchange(byte[] rgbData)
{
byte[] decryptedBytes = null;
if (_rsaKey != null)
{
if (_rsaKey is RSA rsa)
{
decryptedBytes = rsa.Decrypt(rgbData, RSAEncryptionPadding.OaepSHA1);
}
// Add custom decryption logic here.
}
else
{
throw new CryptographicUnexpectedOperationException(
"Cryptography_MissingKey");
}
return decryptedBytes;
}
}
}
//
// This code example produces the following output:
//
// Data to encrypt : Sample Contoso encryption application.
// Encrypted data: Khasdf-3248&$%23
// Data decrypted : Sample Contoso encryption application.
//
// This sample completed successfully; press Enter to exit.
Imports System.Security.Cryptography
Namespace Contoso
Public Class ContosoDeformatter
Inherits AsymmetricKeyExchangeDeformatter
Private rsaKey As RSA
' Default constructor.
Public Sub New()
End Sub
' Constructor with the public key to use for encryption.
Public Sub New(ByVal key As AsymmetricAlgorithm)
SetKey(key)
End Sub
' Set the public key for encyption operations.
Public Overrides Sub SetKey(ByVal key As AsymmetricAlgorithm)
If (Not key Is Nothing) Then
rsaKey = CType(key, RSA)
Else
Throw New ArgumentNullException("key")
End If
End Sub
' Disallow access to the parameters of the formatter.
Public Overrides ReadOnly Property Parameters() As String
Get
Return Nothing
End Get
Set(ByVal Value As String)
End Set
End Property
' Create the encrypted key exchange data from the specified input
' data. This method uses the RSA class only. To
' support additional providers or provide custom decryption logic,
' add logic to this member.
Public Overrides Function DecryptKeyExchange(
ByVal rgbData() As Byte) As Byte()
Dim decryptedBytes() As Byte
If (Not rsaKey Is Nothing) Then
If (TypeOf (rsaKey) Is RSA) Then
Dim rsa As RSA
rsa = CType(rsaKey, RSA)
decryptedBytes = rsa.Decrypt(rgbData, RSAEncryptionPadding.OaepSHA1)
End If
' Add custom decryption logic here.
Else
Throw New CryptographicUnexpectedOperationException(
"Cryptography_MissingKey")
End If
Return decryptedBytes
End Function
End Class
End Namespace
'
' This code example produces the following output:
'
' Data to encrypt : Sample Contoso encryption application.
' Encrypted data: Kh34dfg-(*&834d+3
' Data decrypted : Sample Contoso encryption application.
'
' This sample completed successfully; press Exit to continue.
備註
非對稱金鑰交換變形器解密金鑰交換資料。
金鑰交換允許發送者創造秘密資訊,例如可作為對稱加密演算法金鑰的隨機資料,並利用加密方式將其傳送給預定的接收者。
注意事項
強烈建議您不要僅憑基本功能自行創建金鑰交換方法,因為許多細節必須謹慎執行,才能使金鑰交換成功。
建構函式
| 名稱 | Description |
|---|---|
| AsymmetricKeyExchangeDeformatter() |
初始化 AsymmetricKeyExchangeDeformatter 的新執行個體。 |
屬性
| 名稱 | Description |
|---|---|
| Parameters |
當在衍生類別中被覆寫時,會取得或設定非對稱金鑰交換的參數。 |
方法
| 名稱 | Description |
|---|---|
| DecryptKeyExchange(Byte[]) |
當在派生類別中覆寫時,會從加密的金鑰交換資料中提取秘密資訊。 |
| Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
| GetHashCode() |
做為預設哈希函式。 (繼承來源 Object) |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| SetKey(AsymmetricAlgorithm) |
當在派生類別中覆寫時,會設定私鑰用於解密秘密資訊。 |
| ToString() |
傳回表示目前 物件的字串。 (繼承來源 Object) |