public override PaillierParameters 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 PaillierParameters x_params = new PaillierParameters(); // set the public values of the parameters x_params.N = o_key_struct.N.getBytes(); x_params.G = o_key_struct.G.getBytes(); x_params.Padding = o_key_struct.Padding; // if required, include the private value, X if (p_include_private_params) { x_params.Lambda = o_key_struct.Lambda.getBytes(); x_params.Miu = o_key_struct.Miu.getBytes(); } else { // ensure that we zero the value x_params.Lambda = new byte[1]; x_params.Miu = new byte[1]; } return(x_params); }
public override void FromXmlString(String p_string) { // create the params that we will use as the result PaillierParameters x_params = new PaillierParameters(); // create a text reader using a string reader XmlTextReader x_reader = new XmlTextReader(new System.IO.StringReader(p_string)); // run through the elements in the xml string while (x_reader.Read()) { // we are only interested in processing start nodes if (true || x_reader.IsStartElement()) { switch (x_reader.Name) { case "N": // set the value for N x_params.N = Convert.FromBase64String(x_reader.ReadString()); break; case "G": // set the value for G x_params.G = Convert.FromBase64String(x_reader.ReadString()); break; case "Padding": // set the padding mode x_params.Padding = (PaillierPaddingMode)Enum.Parse(typeof(PaillierPaddingMode), x_reader.ReadString()); break; case "Lambda": // set the value for Lambda (this would not be found in a // string that was generated by excluding the private // elements. x_params.Lambda = Convert.FromBase64String(x_reader.ReadString()); break; case "Miu": // set the value for Lambda (this would not be found in a // string that was generated by excluding the private // elements. x_params.Miu = Convert.FromBase64String(x_reader.ReadString()); break; } } } // Import the result ImportParameters(x_params); }
public override void ImportParameters(PaillierParameters p_parameters) { // obtain the big integer values from the byte parameter values o_key_struct.N = new BigInteger(p_parameters.N); o_key_struct.G = new BigInteger(p_parameters.G); o_key_struct.Padding = p_parameters.Padding; if (p_parameters.Lambda != null && p_parameters.Lambda.Length > 0 && p_parameters.Miu != null && p_parameters.Miu.Length > 0) { o_key_struct.Lambda = new BigInteger(p_parameters.Lambda); o_key_struct.Miu = new BigInteger(p_parameters.Miu); } // set the length of the key based on the import KeySizeValue = o_key_struct.N.bitCount(); }
public override string ToXmlString(bool p_include_private) { PaillierParameters x_params = ExportParameters(p_include_private); // create a new string builder StringBuilder x_sb = new StringBuilder(); // add the header x_sb.Append("<PaillierKeyValue>"); // add the public elements from the parameters x_sb.Append("<N>" + Convert.ToBase64String(x_params.N) + "</N>"); x_sb.Append("<G>" + Convert.ToBase64String(x_params.G) + "</G>"); //x_sb.Append("<Padding>" + Padding.ToString() + "</Padding>"); x_sb.Append("<Padding>" + x_params.Padding.ToString() + "</Padding>"); if (p_include_private) { // we need to include X, which is the part of private key x_sb.Append("<Lambda>" + Convert.ToBase64String(x_params.Lambda) + "</Lambda>"); x_sb.Append("<Miu>" + Convert.ToBase64String(x_params.Miu) + "</Miu>"); } // add the final element x_sb.Append("</PaillierKeyValue>"); return(x_sb.ToString()); }
public abstract void ImportParameters(PaillierParameters p_parameters);