Files
Dec2017-Script-Dump/mscorlib/System/Security/Cryptography/RSAPKCS1KeyExchangeFormatter.cs
T
2026-06-04 11:42:34 +02:00

125 lines
5.2 KiB
C#

using System;
using System.Runtime.InteropServices;
using Mono.Security.Cryptography;
namespace System.Security.Cryptography
{
/// <summary>Creates the PKCS#1 key exchange data using <see cref="T:System.Security.Cryptography.RSA" />.</summary>
// Token: 0x02000520 RID: 1312
[ComVisible(true)]
public class RSAPKCS1KeyExchangeFormatter : AsymmetricKeyExchangeFormatter
{
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Cryptography.RSAPKCS1KeyExchangeFormatter" /> class.</summary>
// Token: 0x06003048 RID: 12360 RVA: 0x0009DEA0 File Offset: 0x0009C0A0
public RSAPKCS1KeyExchangeFormatter()
{
}
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Cryptography.RSAPKCS1KeyExchangeFormatter" /> class with the specified key.</summary>
/// <param name="key">The instance of the <see cref="T:System.Security.Cryptography.RSA" /> algorithm that holds the public key. </param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="key " />is null.</exception>
// Token: 0x06003049 RID: 12361 RVA: 0x0009DEA8 File Offset: 0x0009C0A8
public RSAPKCS1KeyExchangeFormatter(AsymmetricAlgorithm key)
{
this.SetRSAKey(key);
}
/// <summary>Gets or sets the random number generator algorithm to use in the creation of the key exchange.</summary>
/// <returns>The instance of a random number generator algorithm to use.</returns>
// Token: 0x17000982 RID: 2434
// (get) Token: 0x0600304A RID: 12362 RVA: 0x0009DEB8 File Offset: 0x0009C0B8
// (set) Token: 0x0600304B RID: 12363 RVA: 0x0009DEC0 File Offset: 0x0009C0C0
public RandomNumberGenerator Rng
{
get
{
return this.random;
}
set
{
this.random = value;
}
}
/// <summary>Gets the parameters for the PKCS #1 key exchange.</summary>
/// <returns>An XML string containing the parameters of the PKCS #1 key exchange operation.</returns>
// Token: 0x17000983 RID: 2435
// (get) Token: 0x0600304C RID: 12364 RVA: 0x0009DECC File Offset: 0x0009C0CC
public override string Parameters
{
get
{
return "<enc:KeyEncryptionMethod enc:Algorithm=\"http://www.microsoft.com/xml/security/algorithm/PKCS1-v1.5-KeyEx\" xmlns:enc=\"http://www.microsoft.com/xml/security/encryption/v1.0\" />";
}
}
/// <summary>Creates the encrypted key exchange data from the specified input data.</summary>
/// <returns>The encrypted key exchange data to be sent to the intended recipient.</returns>
/// <param name="rgbData">The secret information to be passed in the key exchange. </param>
/// <exception cref="T:System.Security.Cryptography.CryptographicException">
/// <paramref name="rgbData " />is too big.</exception>
/// <exception cref="T:System.Security.Cryptography.CryptographicUnexpectedOperationException">The key is null.</exception>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.KeyContainerPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// </PermissionSet>
// Token: 0x0600304D RID: 12365 RVA: 0x0009DED4 File Offset: 0x0009C0D4
public override byte[] CreateKeyExchange(byte[] rgbData)
{
if (rgbData == null)
{
throw new ArgumentNullException("rgbData");
}
if (this.rsa == null)
{
string text = Locale.GetText("No RSA key specified");
throw new CryptographicUnexpectedOperationException(text);
}
if (this.random == null)
{
this.random = RandomNumberGenerator.Create();
}
return PKCS1.Encrypt_v15(this.rsa, this.random, rgbData);
}
/// <summary>Creates the encrypted key exchange data from the specified input data.</summary>
/// <returns>The encrypted key exchange data to be sent to the intended recipient.</returns>
/// <param name="rgbData">The secret information to be passed in the key exchange. </param>
/// <param name="symAlgType">This parameter is not used in the current version. </param>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.KeyContainerPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// </PermissionSet>
// Token: 0x0600304E RID: 12366 RVA: 0x0009DF38 File Offset: 0x0009C138
public override byte[] CreateKeyExchange(byte[] rgbData, Type symAlgType)
{
return this.CreateKeyExchange(rgbData);
}
// Token: 0x0600304F RID: 12367 RVA: 0x0009DF44 File Offset: 0x0009C144
private void SetRSAKey(AsymmetricAlgorithm key)
{
if (key == null)
{
throw new ArgumentNullException("key");
}
this.rsa = (RSA)key;
}
/// <summary>Sets the public key to use for encrypting the key exchange data.</summary>
/// <param name="key">The instance of the <see cref="T:System.Security.Cryptography.RSA" /> algorithm that holds the public key. </param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="key " />is null.</exception>
// Token: 0x06003050 RID: 12368 RVA: 0x0009DF64 File Offset: 0x0009C164
public override void SetKey(AsymmetricAlgorithm key)
{
this.SetRSAKey(key);
}
// Token: 0x040013A1 RID: 5025
private RSA rsa;
// Token: 0x040013A2 RID: 5026
private RandomNumberGenerator random;
}
}