System.Security.Cryptography.AsymmetricAlgorithm.GetNamedParam C# (CSharp) Method

GetNamedParam() static private method

static private GetNamedParam ( string xml, string param ) : byte[]
xml string
param string
return byte[]
		internal static byte [] GetNamedParam (string xml, string param)
		{
			string start_element = "<" + param + ">";
			int start = xml.IndexOf (start_element);
			if (start == -1)
				return null;

			string end_element = "</" + param + ">";
			int end = xml.IndexOf (end_element);
			if ((end == -1) || (end <= start))
				return null;

			start += start_element.Length;

			string base64 = xml.Substring (start, end - start);
			return Convert.FromBase64String (base64);
		}
	}

Usage Example

Beispiel #1
0
        /// <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>
        public override void FromXmlString(string xmlString)
        {
            if (xmlString == null)
            {
                throw new ArgumentNullException("xmlString");
            }
            RSAParameters parameters = default(RSAParameters);

            try
            {
                parameters.P        = AsymmetricAlgorithm.GetNamedParam(xmlString, "P");
                parameters.Q        = AsymmetricAlgorithm.GetNamedParam(xmlString, "Q");
                parameters.D        = AsymmetricAlgorithm.GetNamedParam(xmlString, "D");
                parameters.DP       = AsymmetricAlgorithm.GetNamedParam(xmlString, "DP");
                parameters.DQ       = AsymmetricAlgorithm.GetNamedParam(xmlString, "DQ");
                parameters.InverseQ = AsymmetricAlgorithm.GetNamedParam(xmlString, "InverseQ");
                parameters.Exponent = AsymmetricAlgorithm.GetNamedParam(xmlString, "Exponent");
                parameters.Modulus  = AsymmetricAlgorithm.GetNamedParam(xmlString, "Modulus");
                this.ImportParameters(parameters);
            }
            catch (Exception inner)
            {
                this.ZeroizePrivateKey(parameters);
                throw new CryptographicException(Locale.GetText("Couldn't decode XML"), inner);
            }
            finally
            {
                this.ZeroizePrivateKey(parameters);
            }
        }
All Usage Examples Of System.Security.Cryptography.AsymmetricAlgorithm::GetNamedParam