This commit is contained in:
niko
2026-06-04 11:42:34 +02:00
parent f39ba70a9f
commit e720b98cd1
7488 changed files with 2493818 additions and 0 deletions
@@ -0,0 +1,177 @@
using System;
using System.Runtime.InteropServices;
using System.Text;
namespace System.Security.Cryptography
{
/// <summary>Represents the base class from which all implementations of the <see cref="T:System.Security.Cryptography.RSA" /> algorithm inherit.</summary>
// Token: 0x0200051B RID: 1307
[ComVisible(true)]
public abstract class RSA : AsymmetricAlgorithm
{
/// <summary>Creates an instance of the default implementation of the <see cref="T:System.Security.Cryptography.RSA" /> algorithm.</summary>
/// <returns>A new instance of the default implementation of <see cref="T:System.Security.Cryptography.RSA" />.</returns>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" />
/// </PermissionSet>
// Token: 0x06003005 RID: 12293 RVA: 0x0009D18C File Offset: 0x0009B38C
public new static RSA Create()
{
return RSA.Create("System.Security.Cryptography.RSA");
}
/// <summary>Creates an instance of the specified implementation of <see cref="T:System.Security.Cryptography.RSA" />.</summary>
/// <returns>A new instance of the specified implementation of <see cref="T:System.Security.Cryptography.RSA" />.</returns>
/// <param name="algName">The name of the implementation of <see cref="T:System.Security.Cryptography.RSA" /> to use. </param>
// Token: 0x06003006 RID: 12294 RVA: 0x0009D198 File Offset: 0x0009B398
public new static RSA Create(string algName)
{
return (RSA)CryptoConfig.CreateFromName(algName);
}
/// <summary>When overridden in a derived class, encrypts the input data using the public key.</summary>
/// <returns>The resulting encryption of the <paramref name="rgb" /> parameter as cipher text.</returns>
/// <param name="rgb">The plain text to be encrypted. </param>
// Token: 0x06003007 RID: 12295
public abstract byte[] EncryptValue(byte[] rgb);
/// <summary>When overridden in a derived class, decrypts the input data using the private key.</summary>
/// <returns>The resulting decryption of the <paramref name="rgb" /> parameter in plain text.</returns>
/// <param name="rgb">The cipher text to be decrypted. </param>
// Token: 0x06003008 RID: 12296
public abstract byte[] DecryptValue(byte[] rgb);
/// <summary>When overridden in a derived class, exports the <see cref="T:System.Security.Cryptography.RSAParameters" />.</summary>
/// <returns>The parameters for <see cref="T:System.Security.Cryptography.DSA" />.</returns>
/// <param name="includePrivateParameters">true to include private parameters; otherwise, false. </param>
// Token: 0x06003009 RID: 12297
public abstract RSAParameters ExportParameters(bool includePrivateParameters);
/// <summary>When overridden in a derived class, imports the specified <see cref="T:System.Security.Cryptography.RSAParameters" />.</summary>
/// <param name="parameters">The parameters for <see cref="T:System.Security.Cryptography.RSA" />. </param>
// Token: 0x0600300A RID: 12298
public abstract void ImportParameters(RSAParameters parameters);
// Token: 0x0600300B RID: 12299 RVA: 0x0009D1A8 File Offset: 0x0009B3A8
internal void ZeroizePrivateKey(RSAParameters parameters)
{
if (parameters.P != null)
{
Array.Clear(parameters.P, 0, parameters.P.Length);
}
if (parameters.Q != null)
{
Array.Clear(parameters.Q, 0, parameters.Q.Length);
}
if (parameters.DP != null)
{
Array.Clear(parameters.DP, 0, parameters.DP.Length);
}
if (parameters.DQ != null)
{
Array.Clear(parameters.DQ, 0, parameters.DQ.Length);
}
if (parameters.InverseQ != null)
{
Array.Clear(parameters.InverseQ, 0, parameters.InverseQ.Length);
}
if (parameters.D != null)
{
Array.Clear(parameters.D, 0, parameters.D.Length);
}
}
/// <summary>Initializes an <see cref="T:System.Security.Cryptography.RSA" /> object from the key information from an XML string.</summary>
/// <param name="xmlString">The XML string containing <see cref="T:System.Security.Cryptography.RSA" /> key information. </param>
/// <exception cref="T:System.ArgumentNullException">The <paramref name="xmlString" /> parameter is null. </exception>
/// <exception cref="T:System.Security.Cryptography.CryptographicException">The format of the <paramref name="xmlString" /> parameter is not valid. </exception>
// Token: 0x0600300C RID: 12300 RVA: 0x0009D284 File Offset: 0x0009B484
public override void FromXmlString(string xmlString)
{
if (xmlString == null)
{
throw new ArgumentNullException("xmlString");
}
RSAParameters rsaparameters = default(RSAParameters);
try
{
rsaparameters.P = AsymmetricAlgorithm.GetNamedParam(xmlString, "P");
rsaparameters.Q = AsymmetricAlgorithm.GetNamedParam(xmlString, "Q");
rsaparameters.D = AsymmetricAlgorithm.GetNamedParam(xmlString, "D");
rsaparameters.DP = AsymmetricAlgorithm.GetNamedParam(xmlString, "DP");
rsaparameters.DQ = AsymmetricAlgorithm.GetNamedParam(xmlString, "DQ");
rsaparameters.InverseQ = AsymmetricAlgorithm.GetNamedParam(xmlString, "InverseQ");
rsaparameters.Exponent = AsymmetricAlgorithm.GetNamedParam(xmlString, "Exponent");
rsaparameters.Modulus = AsymmetricAlgorithm.GetNamedParam(xmlString, "Modulus");
this.ImportParameters(rsaparameters);
}
catch (Exception ex)
{
this.ZeroizePrivateKey(rsaparameters);
throw new CryptographicException(Locale.GetText("Couldn't decode XML"), ex);
}
finally
{
this.ZeroizePrivateKey(rsaparameters);
}
}
/// <summary>Creates and returns an XML string containing the key of the current <see cref="T:System.Security.Cryptography.RSA" /> object.</summary>
/// <returns>An XML string containing the key of the current <see cref="T:System.Security.Cryptography.RSA" /> object.</returns>
/// <param name="includePrivateParameters">true to include a public and private RSA key; false to include only the public key. </param>
// Token: 0x0600300D RID: 12301 RVA: 0x0009D3A0 File Offset: 0x0009B5A0
public override string ToXmlString(bool includePrivateParameters)
{
StringBuilder stringBuilder = new StringBuilder();
RSAParameters rsaparameters = this.ExportParameters(includePrivateParameters);
try
{
stringBuilder.Append("<RSAKeyValue>");
stringBuilder.Append("<Modulus>");
stringBuilder.Append(Convert.ToBase64String(rsaparameters.Modulus));
stringBuilder.Append("</Modulus>");
stringBuilder.Append("<Exponent>");
stringBuilder.Append(Convert.ToBase64String(rsaparameters.Exponent));
stringBuilder.Append("</Exponent>");
if (includePrivateParameters)
{
if (rsaparameters.D == null)
{
string text = Locale.GetText("Missing D parameter for the private key.");
throw new ArgumentNullException(text);
}
if (rsaparameters.P == null || rsaparameters.Q == null || rsaparameters.DP == null || rsaparameters.DQ == null || rsaparameters.InverseQ == null)
{
string text2 = Locale.GetText("Missing some CRT parameters for the private key.");
throw new CryptographicException(text2);
}
stringBuilder.Append("<P>");
stringBuilder.Append(Convert.ToBase64String(rsaparameters.P));
stringBuilder.Append("</P>");
stringBuilder.Append("<Q>");
stringBuilder.Append(Convert.ToBase64String(rsaparameters.Q));
stringBuilder.Append("</Q>");
stringBuilder.Append("<DP>");
stringBuilder.Append(Convert.ToBase64String(rsaparameters.DP));
stringBuilder.Append("</DP>");
stringBuilder.Append("<DQ>");
stringBuilder.Append(Convert.ToBase64String(rsaparameters.DQ));
stringBuilder.Append("</DQ>");
stringBuilder.Append("<InverseQ>");
stringBuilder.Append(Convert.ToBase64String(rsaparameters.InverseQ));
stringBuilder.Append("</InverseQ>");
stringBuilder.Append("<D>");
stringBuilder.Append(Convert.ToBase64String(rsaparameters.D));
stringBuilder.Append("</D>");
}
stringBuilder.Append("</RSAKeyValue>");
}
catch
{
this.ZeroizePrivateKey(rsaparameters);
throw;
}
return stringBuilder.ToString();
}
}
}