コード例 #1
0
        public void PointCompress()
        {
            Assert.That(ECPoint.Decode(new byte[1]), Is.EqualTo(ECPoint.Infinity));
            Assert.That(ECPoint.Infinity.Encode(true), Is.EquivalentTo(new byte[1]));
            Assert.That(ECPoint.Infinity.Encode(false), Is.EquivalentTo(new byte[1]));

            Assert.Throws <FormatException>(() => ECPoint.Decode(new byte[] { 0x00, 0x00 }));

            var p1 = ECPoint.Decode(Encoders.Hex.GetBytes("0279BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798"));
            var p2 = ECPoint.Decode(Encoders.Hex.GetBytes("0479BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8"));

            Assert.AreEqual(p1, p2);

            Assert.That(
                Encoders.Hex.GetString(p1.Encode(true)),
                Does.Contain("0279BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798").IgnoreCase);

            Assert.That(
                Encoders.Hex.GetString(p1.Encode(false)),
                Does.Contain("0479BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8").IgnoreCase);

            Assert.That(
                Encoders.Hex.GetString(p2.Encode(true)),
                Does.Contain("0279BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798").IgnoreCase);

            Assert.That(
                Encoders.Hex.GetString(p2.Encode(false)),
                Does.Contain("0479BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8").IgnoreCase);
        }
コード例 #2
0
 public bool Points(string encoded)
 {
     try
     {
         var p = ECPoint.Decode(Encoders.Hex.GetBytes(encoded));
         return(true);
     }
     catch (FormatException)
     {
         return(false);
     }
 }