Esempio n. 1
0
        public void TestFromBytes()
        {
            byte[] input1 = { 0 };
            Action action = () => ECPoint.FromBytes(input1, ECCurve.Secp256k1);

            action.Should().Throw <FormatException>();

            byte[] input2 = { 4,  121, 190, 102, 126, 249, 220, 187, 172,  85, 160, 98, 149, 206, 135,  11,  7,   2, 155, 252, 219, 45, 206,  40, 217,  89, 242, 129, 91,  22, 248, 23, 152, 72,
                              58, 218, 119,  38, 163, 196, 101,  93, 164, 251, 252, 14,  17,   8, 168, 253, 23, 180,  72, 166, 133, 84,  25, 156,  71, 208, 143, 251, 16, 212, 184 };
            ECPoint.FromBytes(input2, ECCurve.Secp256k1).Should().Be(ECCurve.Secp256k1.G);

            byte[] input3 = { 2, 121, 190, 102, 126, 249, 220, 187, 172, 85, 160, 98, 149, 206, 135, 11, 7, 2, 155, 252, 219, 45, 206, 40, 217, 89, 242, 129, 91, 22, 248, 23, 152 };
            ECPoint.FromBytes(input3, ECCurve.Secp256k1).Should().Be(ECCurve.Secp256k1.G);
            ECPoint.FromBytes(input2.Skip(1).ToArray(), ECCurve.Secp256k1).Should().Be(ECCurve.Secp256k1.G);

            byte[] input4 = GeneratePrivateKey(72);
            ECPoint.FromBytes(input4, ECCurve.Secp256k1).Should().Be(new ECPoint(new ECFieldElement(BigInteger.Parse("3634473727541135791764834762056624681715094789735830699031648" +
                                                                                                                     "273128038409767"), ECCurve.Secp256k1), new ECFieldElement(BigInteger.Parse("18165245710263168158644330920009617039772504630129940696140050972160274286151"),
                                                                                                                                                                                ECCurve.Secp256k1), ECCurve.Secp256k1));

            byte[] input5 = GeneratePrivateKey(96);
            ECPoint.FromBytes(input5, ECCurve.Secp256k1).Should().Be(new ECPoint(new ECFieldElement(BigInteger.Parse("1780731860627700044960722568376592200742329637303199754547598" +
                                                                                                                     "369979440671"), ECCurve.Secp256k1), new ECFieldElement(BigInteger.Parse("14532552714582660066924456880521368950258152170031413196862950297402215317055"),
                                                                                                                                                                             ECCurve.Secp256k1), ECCurve.Secp256k1));

            byte[] input6 = GeneratePrivateKey(104);
            ECPoint.FromBytes(input6, ECCurve.Secp256k1).Should().Be(new ECPoint(new ECFieldElement(BigInteger.Parse("3634473727541135791764834762056624681715094789735830699031648" +
                                                                                                                     "273128038409767"), ECCurve.Secp256k1), new ECFieldElement(BigInteger.Parse("18165245710263168158644330920009617039772504630129940696140050972160274286151"),
                                                                                                                                                                                ECCurve.Secp256k1), ECCurve.Secp256k1));
        }