/// <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(); } DHParameters dhParams = new DHParameters(); try { XmlDocument sp = new XmlDocument(); sp.LoadXml(xmlString); XmlNode se = sp.DocumentElement; if (se.Name != "DHKeyValue") { throw new CryptographicException(); } XmlNode sl; sl = se.SelectSingleNode("P"); dhParams.P = Convert.FromBase64String(sl.ToString()); sl = se.SelectSingleNode("G"); dhParams.G = Convert.FromBase64String(sl.ToString()); sl = se.SelectSingleNode("X"); dhParams.X = Convert.FromBase64String(sl.ToString()); 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);