Пример #1
0
        static void TestPublicKey()
        {
            Console.WriteLine("TestPublicKey");
            SecretKey sec;

            sec.SetByCSPRNG();
            PublicKey pub = sec.GetPublicKey();
            string    s   = pub.GetHexStr();

            Console.WriteLine("pub={0}", s);
            {
                PublicKey pub2;
                pub2.SetStr(s);
                assert("pub.SetStr", pub.IsEqual(pub2));
            }
            {
                PublicKey pub2;
                byte[]    buf = pub.Serialize();
                pub2.Deserialize(buf);
                assert("serialize", pub2.IsEqual(pub));
            }
            {
                PublicKey pub2 = pub;
                pub.Neg();
                pub.Add(pub2);
                assert("pub is zero", pub.IsZero());
            }
            {
                PublicKey pub2 = pub;
                for (int i = 0; i < 5; i++)
                {
                    pub2.Add(pub);
                }
                PublicKey pub3 = pub;
                SecretKey t;
                t.SetHexStr("5");
                pub3.Mul(t);
                assert("pub mul", pub2.IsEqual(pub3));
            }
        }