public override void ImportParameters(ElGamalParameters p_parameters)
 {
     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);
     }
     KeySizeValue = o_key_struct.P.bitCount();
 }
Ejemplo n.º 2
0
        public override string ToXmlString(bool p_include_private)
        {
            ElGamalParameters x_params = ExportParameters(p_include_private);

            StringBuilder x_sb = new StringBuilder();

            x_sb.Append("<ElGamalKeyValue>");

            x_sb.Append("<P>" + Convert.ToBase64String(x_params.P) + "</P>");
            x_sb.Append("<G>" + Convert.ToBase64String(x_params.G) + "</G>");
            x_sb.Append("<Y>" + Convert.ToBase64String(x_params.Y) + "</Y>");
            if (p_include_private)
            {
                x_sb.Append("<X>" + Convert.ToBase64String(x_params.X) + "</X>");
            }

            x_sb.Append("</ElGamalKeyValue>");
            return(x_sb.ToString());
        }
Ejemplo n.º 3
0
        public override void FromXmlString(String p_string)
        {
            ElGamalParameters x_params = new ElGamalParameters();

            XmlTextReader x_reader =
                new XmlTextReader(new System.IO.StringReader(p_string));

            while (x_reader.Read())
            {
                if (true || x_reader.IsStartElement())
                {
                    switch (x_reader.Name)
                    {
                    case "P":
                        x_params.P =
                            Convert.FromBase64String(x_reader.ReadString());
                        break;

                    case "G":
                        x_params.G =
                            Convert.FromBase64String(x_reader.ReadString());
                        break;

                    case "Y":
                        x_params.Y =
                            Convert.FromBase64String(x_reader.ReadString());
                        break;

                    case "X":
                        x_params.X =
                            Convert.FromBase64String(x_reader.ReadString());
                        break;
                    }
                }
            }

            ImportParameters(x_params);
        }
        public override ElGamalParameters ExportParameters(bool
                                                           p_include_private_params)
        {
            if (NeedToGenerateKey())
            {
                CreateKeyPair(KeySizeValue);
            }

            ElGamalParameters x_params = new ElGamalParameters();

            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 (p_include_private_params)
            {
                x_params.X = o_key_struct.X.getBytes();
            }
            else
            {
                x_params.X = new byte[1];
            }
            return(x_params);
        }
Ejemplo n.º 5
0
 public abstract void ImportParameters(ElGamalParameters p_parameters);