/// <summary> /// Imports the specified <see cref="DHParameters"/>. /// </summary> /// <param name="parameters">The parameters for <see cref="DiffieHellman"/>.</param> /// <exception cref="CryptographicException"><paramref name="P"/> or <paramref name="G"/> is a null reference (<b>Nothing</b> in Visual Basic) -or- <paramref name="P"/> is not a prime number.</exception> public override void ImportParameters(DHParameters parameters) { if (parameters.P == null) { throw new CryptographicException("Missing P value."); } if (parameters.G == null) { throw new CryptographicException("Missing G value."); } BigInteger p = new BigInteger(parameters.P), g = new BigInteger(parameters.G), x = null; if (parameters.X != null) { x = new BigInteger(parameters.X); } Initialize(p, g, x, 0, true); }
/// <summary> /// Reconstructs a <see cref="DiffieHellman"/> object from an XML string. /// </summary> /// <param name="xmlString">The XML string to use to reconstruct the DiffieHellman object.</param> /// <exception cref="CryptographicException">One of the values in the XML string is invalid.</exception> public override void FromXmlString(string xmlString) { if (xmlString == null) { throw new ArgumentNullException("xmlString"); } DHParameters dhParams = new DHParameters(); try { SecurityParser sp = new SecurityParser(); sp.LoadXml(xmlString); SecurityElement se = sp.ToXml(); if (se.Tag != "DHKeyValue") { throw new CryptographicException(); } dhParams.P = GetNamedParam(se, "P"); dhParams.G = GetNamedParam(se, "G"); dhParams.X = GetNamedParam(se, "X"); ImportParameters(dhParams); } finally { if (dhParams.P != null) { Array.Clear(dhParams.P, 0, dhParams.P.Length); } if (dhParams.G != null) { Array.Clear(dhParams.G, 0, dhParams.G.Length); } if (dhParams.X != null) { Array.Clear(dhParams.X, 0, dhParams.X.Length); } } }
/// <summary> /// When overridden in a derived class, imports the specified <see cref="DHParameters"/>. /// </summary> /// <param name="parameters">The parameters for Diffie-Hellman.</param> public abstract void ImportParameters(DHParameters parameters);