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];
            }
            // return the parameter set
            return(x_params);
        }
Beispiel #2
0
 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();
 }
 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();
 }
Beispiel #4
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());
        }
Beispiel #5
0
        public override void FromXmlString(String p_string)
        {
            // create the params that we will use as the result
            ElGamalParameters x_params = new ElGamalParameters();
            // 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 "P":
                        // set the value for P
                        x_params.P =
                            Convert.FromBase64String(x_reader.ReadString());
                        break;

                    case "G":
                        // set the value for G
                        x_params.G =
                            Convert.FromBase64String(x_reader.ReadString());
                        break;

                    case "Y":
                        // set the value for Y
                        x_params.Y =
                            Convert.FromBase64String(x_reader.ReadString());
                        break;

                    case "X":
                        // set the value for X (this would not be found in a
                        // string that was generated by excluding the private
                        // elements.
                        x_params.X =
                            Convert.FromBase64String(x_reader.ReadString());
                        break;
                    }
                }
            }
            // Import the result
            ImportParameters(x_params);
        }
Beispiel #6
0
        public override string ToXmlString(bool p_include_private)
        {
            ElGamalParameters x_params = ExportParameters(p_include_private);
            // create a new string builder
            StringBuilder x_sb = new StringBuilder();

            // add the header
            x_sb.Append("<ElGamalKeyValue>");
            // add the public elements from the parameters
            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)
            {
                // we need to include X, which is the part of private key
                x_sb.Append("<X>" + Convert.ToBase64String(x_params.X) + "</X>");
            }
            // add the final element
            x_sb.Append("</ElGamalKeyValue>");
            return(x_sb.ToString());
        }
Beispiel #7
0
        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);
        }
Beispiel #8
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);
        }
Beispiel #9
0
 public abstract void ImportParameters(ElGamalParameters p_parameters);