public override void FromXmlString(String p_string) { // create the params that we will use as the result ElGamalParameters x_params = new ElGamalParameters(); XDocument xdoc = XDocument.Parse(p_string); XElement root = xdoc.Root; if (root != null) { // set the value for P XElement xelP = root.Element("P"); if (xelP != null) x_params.P = Convert.FromBase64String(xelP.Value); // set the value for G XElement xelG = root.Element("G"); if (xelG != null) x_params.G = Convert.FromBase64String(xelG.Value); // set the value for Y XElement xelY = root.Element("Y"); if (xelY != null) x_params.Y = Convert.FromBase64String(xelY.Value); // set the value for X (this would not be found in a string // that was generated by excluding the private elements. XElement xelX = root.Element("X"); if (xelX != null) x_params.X = Convert.FromBase64String(xelX.Value); } // Import the result ImportParameters(x_params); }
/// <summary> /// Configure the key settings for this algorithm instance from /// a set of key parameters /// </summary> /// <param name="p_parameters"></param> public override void ImportParameters(ElGamalParameters p_parameters) { // obtain the big integer values from the byte parameter values o_key_struct.P = new BigInteger(p_parameters.P); o_key_struct.G = new BigInteger(p_parameters.G); o_key_struct.Y = new BigInteger(p_parameters.Y); if (p_parameters.X != null && p_parameters.X.Length > 0) { o_key_struct.X = new BigInteger(p_parameters.X); } // set the length of the key based on the import KeySizeValue = o_key_struct.P.bitCount(); }
public abstract void ImportParameters(ElGamalParameters p_parameters);
public override ElGamalParameters ExportParameters(bool p_include_private_params) { if (NeedToGenerateKey()) { // we need to create a new key before we can export CreateKeyPair(KeySizeValue); } // create the parameter set ElGamalParameters x_params = new ElGamalParameters(); // set the public values of the parameters x_params.P = o_key_struct.P.getBytes(); x_params.G = o_key_struct.G.getBytes(); x_params.Y = o_key_struct.Y.getBytes(); // if required, include the private value, X if (p_include_private_params) { x_params.X = o_key_struct.X.getBytes(); } else { // ensure that we zero the value x_params.X = new byte[1]; } // retuen the parameter set return x_params; }