AsymmetricKeyExchangeDeformatter 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
代表從中衍生所有非對稱金鑰交換變形項的基底類型。
public ref class AsymmetricKeyExchangeDeformatter abstract
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public abstract class AsymmetricKeyExchangeDeformatter
public abstract class AsymmetricKeyExchangeDeformatter
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class AsymmetricKeyExchangeDeformatter
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
type AsymmetricKeyExchangeDeformatter = class
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.
備註
非對稱金鑰交換轉換程式會解密金鑰交換數據。
密鑰交換可讓傳送者建立秘密資訊,例如可用來作為對稱加密演算法中密鑰的隨機數據,並使用加密將它傳送給預定收件者。
警告
強烈建議您不要嘗試從提供的基本功能建立自己的密鑰交換方法,因為必須仔細執行作業的許多詳細數據,金鑰交換才能成功。
建構函式
AsymmetricKeyExchangeDeformatter() |
初始化 AsymmetricKeyExchangeDeformatter 的新執行個體。 |
屬性
Parameters |
在衍生類別中覆寫時,取得或設定非對稱金鑰交換的參數。 |
方法
DecryptKeyExchange(Byte[]) |
在衍生類別中覆寫時,從加密的金鑰交換資料中擷取秘密資訊。 |
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
GetHashCode() |
做為預設雜湊函式。 (繼承來源 Object) |
GetType() |
取得目前執行個體的 Type。 (繼承來源 Object) |
MemberwiseClone() |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
SetKey(AsymmetricAlgorithm) |
在衍生類別中覆寫時,設定要用來解密機密資訊的私密金鑰。 |
ToString() |
傳回代表目前物件的字串。 (繼承來源 Object) |