本文整理匯總了C#中System.Security.Cryptography.AsymmetricKeyExchangeDeformatter類的典型用法代碼示例。如果您正苦於以下問題:C# AsymmetricKeyExchangeDeformatter類的具體用法?C# AsymmetricKeyExchangeDeformatter怎麽用?C# AsymmetricKeyExchangeDeformatter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
AsymmetricKeyExchangeDeformatter類屬於System.Security.Cryptography命名空間,在下文中一共展示了AsymmetricKeyExchangeDeformatter類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ContosoDeformatter
//引入命名空間
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("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 RSACryptoServiceProvider 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 RSACryptoServiceProvider)
{
RSACryptoServiceProvider serviceProvder =
(RSACryptoServiceProvider)rsaKey;
decryptedBytes = serviceProvder.Decrypt(rgbData, true);
}
// Add custom decryption logic here.
}
else
{
throw new CryptographicUnexpectedOperationException(
"Cryptography_MissingKey");
}
return decryptedBytes;
}
}
}
//
輸出:
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.