Ejemplo n.º 1
0
        public void CalculateSharedSecretWithSelfPubKey()
        {
            using (var secp256k1 = new Secp256k1())
            {
                Span <byte> privateKey   = "90cc2eb9f4ac1562546c9899b5a68fc98a8add85a606abd506058e75ce583f49".HexToBytes();
                Span <byte> publicKey    = stackalloc byte[64];
                Span <byte> sharedSecret = stackalloc byte[32];

                secp256k1.PublicKeyCreate(publicKey, privateKey);
                secp256k1.CalculateSharedSecret(sharedSecret, publicKey, privateKey);

                Assert.Equal(32, sharedSecret.Length);
                Assert.Equal("3e9a315412415ab738658e7f2119c434e7c2112862315d0af756d03d923874ae", sharedSecret.ToHexString());
            }
        }
Ejemplo n.º 2
0
        public void CalculateSharedSecretWithAnotherPubKey()
        {
            using (var secp256k1 = new Secp256k1())
            {
                Span <byte> privateKey   = "90cc2eb9f4ac1562546c9899b5a68fc98a8add85a606abd506058e75ce583f49".HexToBytes();
                Span <byte> privateKey2  = "e815acba8fcf085a0b4141060c13b8017a08da37f2eb1d6a5416adbb621560ef".HexToBytes();
                Span <byte> publicKey    = stackalloc byte[64];
                Span <byte> sharedSecret = stackalloc byte[32];

                secp256k1.PublicKeyCreate(publicKey, privateKey2);
                secp256k1.CalculateSharedSecret(sharedSecret, publicKey, privateKey);

                Assert.Equal(32, sharedSecret.Length);
                Assert.Equal("8fd6cc22898c5bddf1b6e596f131cea5f09ef2122f57852a90137959101bace1", sharedSecret.ToHexString());
            }
        }