using System; using System.Runtime.InteropServices; using System.Text; namespace System.Security.Cryptography { /// Represents the base class from which all implementations of the algorithm inherit. // Token: 0x0200051B RID: 1307 [ComVisible(true)] public abstract class RSA : AsymmetricAlgorithm { /// Creates an instance of the default implementation of the algorithm. /// A new instance of the default implementation of . /// /// /// // Token: 0x06003005 RID: 12293 RVA: 0x0009D18C File Offset: 0x0009B38C public new static RSA Create() { return RSA.Create("System.Security.Cryptography.RSA"); } /// Creates an instance of the specified implementation of . /// A new instance of the specified implementation of . /// The name of the implementation of to use. // Token: 0x06003006 RID: 12294 RVA: 0x0009D198 File Offset: 0x0009B398 public new static RSA Create(string algName) { return (RSA)CryptoConfig.CreateFromName(algName); } /// When overridden in a derived class, encrypts the input data using the public key. /// The resulting encryption of the parameter as cipher text. /// The plain text to be encrypted. // Token: 0x06003007 RID: 12295 public abstract byte[] EncryptValue(byte[] rgb); /// When overridden in a derived class, decrypts the input data using the private key. /// The resulting decryption of the parameter in plain text. /// The cipher text to be decrypted. // Token: 0x06003008 RID: 12296 public abstract byte[] DecryptValue(byte[] rgb); /// When overridden in a derived class, exports the . /// The parameters for . /// true to include private parameters; otherwise, false. // Token: 0x06003009 RID: 12297 public abstract RSAParameters ExportParameters(bool includePrivateParameters); /// When overridden in a derived class, imports the specified . /// The parameters for . // 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); } } /// Initializes an object from the key information from an XML string. /// The XML string containing key information. /// The parameter is null. /// The format of the parameter is not valid. // 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); } } /// Creates and returns an XML string containing the key of the current object. /// An XML string containing the key of the current object. /// true to include a public and private RSA key; false to include only the public key. // 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(""); stringBuilder.Append(""); stringBuilder.Append(Convert.ToBase64String(rsaparameters.Modulus)); stringBuilder.Append(""); stringBuilder.Append(""); stringBuilder.Append(Convert.ToBase64String(rsaparameters.Exponent)); stringBuilder.Append(""); 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("

"); stringBuilder.Append(Convert.ToBase64String(rsaparameters.P)); stringBuilder.Append("

"); stringBuilder.Append(""); stringBuilder.Append(Convert.ToBase64String(rsaparameters.Q)); stringBuilder.Append(""); stringBuilder.Append(""); stringBuilder.Append(Convert.ToBase64String(rsaparameters.DP)); stringBuilder.Append(""); stringBuilder.Append(""); stringBuilder.Append(Convert.ToBase64String(rsaparameters.DQ)); stringBuilder.Append(""); stringBuilder.Append(""); stringBuilder.Append(Convert.ToBase64String(rsaparameters.InverseQ)); stringBuilder.Append(""); stringBuilder.Append(""); stringBuilder.Append(Convert.ToBase64String(rsaparameters.D)); stringBuilder.Append(""); } stringBuilder.Append("
"); } catch { this.ZeroizePrivateKey(rsaparameters); throw; } return stringBuilder.ToString(); } } }