Esempio n. 1
0
        public void FromPublicKeyGood()
        {
            var pubKey  = PublicKey.FromPrivateKey(PrivateKey.FromWif("Kz3sAkMYRTwnXhi2UieoP4qKfMjpqYq7XWkqYR37pBgc3hqoimuq"));
            var address = Address.FromPublicKey(pubKey);

            Assert.AreEqual(this._goodAddressString, address.ToString());
        }
Esempio n. 2
0
        public void FromPublicKeyBad()
        {
            var pubKey  = PublicKey.FromPrivateKey(PrivateKey.FromWif("L1cT9LpRSSDGTybdoF3yuESbcMQiRLiFiCAvVLmC9BiEXsVXUABE"));
            var address = Address.FromPublicKey(pubKey);

            Assert.AreNotEqual(this._goodAddressString, address.ToString());
        }
Esempio n. 3
0
        public void TestSignature()
        {
            string     privateKeyString = "5J7Yu8zZD5oV9Ex7npmsT3XBbpSdPZPBKBzLLQnXz5JHQVQVfNT";
            PrivateKey privateKey       = PrivateKey.FromWif(privateKeyString);
            var        sign             = Signature.SignString("1", privateKey);

            Console.WriteLine(sign.ToHex());
        }
Esempio n. 4
0
        public void FromWifTestnetUncompressed()
        {
            var wif  = "92jJzK4tbURm1C7udQXxeCBvXHoHJstDXRxAMouPG1k1XUaXdsu";
            var priv = PrivateKey.FromWif(wif);

            Assert.AreEqual(wif, priv.ToWif());
            Assert.AreEqual(Network.TestNet, priv.Network);
            Assert.IsFalse(priv.Compressed);
        }
Esempio n. 5
0
        public void FromWifTestnetCompressed()
        {
            var wif  = "cSdkPxkAjA4HDr5VHgsebAPDEh9Gyub4HK8UJr2DFGGqKKy4K5sG";
            var priv = PrivateKey.FromWif(wif);

            Assert.AreEqual(wif, priv.ToWif());
            Assert.AreEqual(Network.TestNet, priv.Network);
            Assert.IsTrue(priv.Compressed);
        }
Esempio n. 6
0
        public void FromWifLivenetUncompressed()
        {
            var wif  = "5JxgQaFM1FMd38cd14e3mbdxsdSa9iM2BV6DHBYsvGzxkTNQ7Un";
            var priv = PrivateKey.FromWif(wif);

            Assert.AreEqual(wif, priv.ToWif());
            Assert.AreEqual(Network.LiveNet, priv.Network);
            Assert.IsFalse(priv.Compressed);
        }
Esempio n. 7
0
        public void FromWifLivenetCompressed()
        {
            var wif  = "L1cT9LpRSSDGTybdoF3yuESbcMQiRLiFiCAvVLmC9BiEXsVXUABE";
            var priv = PrivateKey.FromWif(wif);

            Assert.AreEqual(wif, priv.ToWif());
            Assert.AreEqual(Network.LiveNet, priv.Network);
            Assert.IsTrue(priv.Compressed);
        }
Esempio n. 8
0
        public void TestPrivateKey()
        {
            string     privateKeyString = "5J7Yu8zZD5oV9Ex7npmsT3XBbpSdPZPBKBzLLQnXz5JHQVQVfNT";
            PrivateKey privateKey       = PrivateKey.FromWif(privateKeyString);

            Console.WriteLine(privateKey.ToString());
            Console.WriteLine(privateKey.GetPublicKey().ToString());
            Assert.AreEqual <string>(privateKeyString, privateKey.ToString(), "Private keys should be equal");
        }
Esempio n. 9
0
        public void MemoEncryptDecrypt2()
        {
            string message      = "hi你好"; // including special charactors
            var    msg          = "d504585e9d604bcf24a2ce19c220e5f7";
            string decryptedMsg = AES.DecryptWithChecksum(PrivateKey.FromWif("5J7Yu8zZD5oV9Ex7npmsT3XBbpSdPZPBKBzLLQnXz5JHQVQVfNT"), PublicKey.FromString("GXC8H1wXTAUWcTtogBmA5EW8TUWLA6T1kAXwMKYtnNuqAe1VCXFD9"), 398450244318460L, Hex.HexToBytes(msg));

            Console.WriteLine(decryptedMsg);
            Assert.AreEqual(message, decryptedMsg);
        }
Esempio n. 10
0
        public void TestSharedSecret()
        {
            string     privateKeyString = "5J7Yu8zZD5oV9Ex7npmsT3XBbpSdPZPBKBzLLQnXz5JHQVQVfNT";
            PrivateKey privateKey       = PrivateKey.FromWif(privateKeyString);
            var        sharedSecret     = privateKey.SharedSecret(privateKey.GetPublicKey());

            Console.WriteLine(Hex.BytesToHex(sharedSecret));
            Assert.AreEqual <string>(Hex.BytesToHex(sharedSecret), "53e731cf6c166a972962e776734f7afbfb320b1b26ddfc32125ecb7c6d6e37aa59f5b0e4ccad49630cc455a9830274c3e2ac7ae43f94f12449250f85e2311a1c", "Shared secret not expected");
        }
Esempio n. 11
0
        public void FromPrivateKeyTestnetUncompressed()
        {
            var priv = PrivateKey.FromWif("92jJzK4tbURm1C7udQXxeCBvXHoHJstDXRxAMouPG1k1XUaXdsu");
            var pub  = PublicKey.FromPrivateKey(priv);

            Assert.AreEqual("0429766f1afa25ca499a51f8e01c292b0255a21a41bb6685564a1607a811ffe92458ee8923b3e93566d0b15778b168fe0027d63d0c7c7561a841222f9f32e13eca", Helpers.GetHexString(pub.ToByteArray()));
            Assert.AreEqual(priv.Compressed, pub.Compressed);
            Assert.AreEqual(priv.Network, pub.Network);
            Assert.AreEqual("n11ww96E2KN7t2K1x3DHjFDQFY1H2UsMdB", pub.ToAddress().ToString());
        }
Esempio n. 12
0
        public void FromPrivateKeyTestnetCompressed()
        {
            var priv = PrivateKey.FromWif("cSdkPxkAjA4HDr5VHgsebAPDEh9Gyub4HK8UJr2DFGGqKKy4K5sG");
            var pub  = PublicKey.FromPrivateKey(priv);

            Assert.AreEqual("0229766f1afa25ca499a51f8e01c292b0255a21a41bb6685564a1607a811ffe924", Helpers.GetHexString(pub.ToByteArray()));
            Assert.AreEqual(priv.Compressed, pub.Compressed);
            Assert.AreEqual(priv.Network, pub.Network);
            Assert.AreEqual("mgY65WSfEmsyYaYPQaXhmXMeBhwp4EcsQW", pub.ToAddress().ToString());
        }
Esempio n. 13
0
        public void FromPrivateKeyLivenetUncompressed()
        {
            var priv = PrivateKey.FromWif("5JxgQaFM1FMd38cd14e3mbdxsdSa9iM2BV6DHBYsvGzxkTNQ7Un");
            var pub  = PublicKey.FromPrivateKey(priv);

            Assert.AreEqual("0429766f1afa25ca499a51f8e01c292b0255a21a41bb6685564a1607a811ffe92458ee8923b3e93566d0b15778b168fe0027d63d0c7c7561a841222f9f32e13eca", Helpers.GetHexString(pub.ToByteArray()));
            Assert.AreEqual(priv.Compressed, pub.Compressed);
            Assert.AreEqual(priv.Network, pub.Network);
            Assert.AreEqual("DQe6BLwtWhq9dv1zy4EUT6AgGg8sVahTX2", pub.ToAddress().ToString());
        }
Esempio n. 14
0
        public void FromPrivateKeyLivenetCompressed()
        {
            var priv = PrivateKey.FromWif("Kz3sAkMYRTwnXhi2UieoP4qKfMjpqYq7XWkqYR37pBgc3hqoimuq");
            var pub  = PublicKey.FromPrivateKey(priv);

            Assert.AreEqual("020d072ff096bf53b7c6c85854655f3eb675c48ca14e3a24dc7cce00524c26a7ba", Helpers.GetHexString(pub.ToByteArray()));
            Assert.AreEqual(priv.Compressed, pub.Compressed);
            Assert.AreEqual(priv.Network, pub.Network);
            Assert.AreEqual("DNXLvN5A356fCvwDVXTAFwv6jQr1m7v9d4", pub.ToAddress().ToString());
        }
Esempio n. 15
0
        public void BsvPrivateKeyTests()
        {
            var hex = "96c132224121b509b7d0a16245e957d9192609c5637c6228311287b1be21627a";
            //var hex2 = "8080808080808080808080808080808080808080808080808080808080808080";
            var wifLivenet = "L2Gkw3kKJ6N24QcDuH4XDqt9cTqsKTVNDGz1CRZhk9cq4auDUbJy";

            var privKey  = new PrivateKey(hex);
            var privKey2 = PrivateKey.FromWif(wifLivenet);

            Assert.Equal(privKey, privKey2);
        }
Esempio n. 16
0
        public void SignVerify()
        {
            var priv      = PrivateKey.FromWif("Kz3sAkMYRTwnXhi2UieoP4qKfMjpqYq7XWkqYR37pBgc3hqoimuq");
            var msg       = new Message("Hello world!");
            var signature = msg.Sign(priv);

            Assert.IsNotNull(signature);
            Assert.AreNotEqual("", signature.ToString());

            Assert.IsTrue(msg.Verify("DNXLvN5A356fCvwDVXTAFwv6jQr1m7v9d4", signature.ToString()));
            Assert.IsFalse(msg.Verify("DHTXvgtoSVGHJGeZN7pSwLWyHY9ek9qdCh", signature.ToString()));
        }
Esempio n. 17
0
        public void MemoEncryptDecrypt()
        {
            string message = "6不6"; // including special charactors
            var    result  = AES.EncryptWithChecksum(PrivateKey.FromWif("5J7Yu8zZD5oV9Ex7npmsT3XBbpSdPZPBKBzLLQnXz5JHQVQVfNT"), PublicKey.FromString("GXC8H1wXTAUWcTtogBmA5EW8TUWLA6T1kAXwMKYtnNuqAe1VCXFD9"), 16087047636745223546L, message);
            var    msg     = Hex.BytesToHex(result);

            Console.WriteLine(Hex.BytesToHex(result));
            string decryptedMsg = AES.DecryptWithChecksum(PrivateKey.FromWif("5J7Yu8zZD5oV9Ex7npmsT3XBbpSdPZPBKBzLLQnXz5JHQVQVfNT"), PublicKey.FromString("GXC8H1wXTAUWcTtogBmA5EW8TUWLA6T1kAXwMKYtnNuqAe1VCXFD9"), 16087047636745223546L, Hex.HexToBytes(msg));

            Console.WriteLine(decryptedMsg);
            Assert.AreEqual(message, decryptedMsg);
        }
Esempio n. 18
0
        public void TestCases()
        {
            const string message = "attack at dawn";

            var aliceKey = PrivateKey.FromWif("L1Ejc5dAigm5XrM3mNptMEsNnHzS7s51YxU7J61ewGshZTKkbmzJ");
            var bobKey   = PrivateKey.FromWif("KxfxrUXSMjJQcb3JgnaaA6MqsrKQ1nBSxvhuigdKRyFiEm6BZDgG");

            {
                var encrypted = "0339e504d6492b082da96e11e8f039796b06cd4855c101e2492a6f10f3e056a9e712c732611c6917ab5c57a1926973bc44a1586e94a783f81d05ce72518d9b0a80e2e13c7ff7d1306583f9cc7a48def5b37fbf2d5f294f128472a6e9c78dede5f5";
                // encrypted broken down:
                // priv.pubkey 0339e504d6492b082da96e11e8f039796b06cd4855c101e2492a6f10f3e056a9e7
                // ivbuf       12c732611c6917ab5c57a1926973bc44
                // encrypted   a1586e94a783f81d05ce72518d9b0a80
                // sig         e2e13c7ff7d1306583f9cc7a48def5b37fbf2d5f294f128472a6e9c78dede5f5

                var alice = new Ecies {
                    PrivateKey = aliceKey, PublicKey = bobKey.CreatePublicKey()
                };
                var bob = new Ecies {
                    PrivateKey = bobKey
                };

                var ciphertext = alice.Encrypt(message);
                Assert.Equal(encrypted, ciphertext.ToHex());

                var decryptedtext = bob.DecryptToUtf8(ciphertext);
                Assert.Equal(message, decryptedtext);
            }

            {
                var encrypted = "0339e504d6492b082da96e11e8f039796b06cd4855c101e2492a6f10f3e056a9e712c732611c6917ab5c57a1926973bc44a1586e94a783f81d05ce72518d9b0a80e2e13c7f";
                // encrypted broken down:
                // priv.pubkey 0339e504d6492b082da96e11e8f039796b06cd4855c101e2492a6f10f3e056a9e7
                // ivbuf       12c732611c6917ab5c57a1926973bc44
                // encrypted   a1586e94a783f81d05ce72518d9b0a80
                // sig         e2e13c7f

                var alice = new Ecies {
                    PrivateKey = aliceKey, PublicKey = bobKey.CreatePublicKey(), ShortTag = true
                };
                var bob = new Ecies {
                    PrivateKey = bobKey, ShortTag = true
                };

                var ciphertext = alice.Encrypt(message);
                Assert.Equal(encrypted, ciphertext.ToHex());

                var decryptedtext = bob.DecryptToUtf8(ciphertext);
                Assert.Equal(message, decryptedtext);
            }

            {
                var encrypted = "12c732611c6917ab5c57a1926973bc44a1586e94a783f81d05ce72518d9b0a80e2e13c7ff7d1306583f9cc7a48def5b37fbf2d5f294f128472a6e9c78dede5f5";
                // encrypted broken down:
                // priv.pubkey
                // ivbuf       12c732611c6917ab5c57a1926973bc44
                // encrypted   a1586e94a783f81d05ce72518d9b0a80
                // sig         e2e13c7ff7d1306583f9cc7a48def5b37fbf2d5f294f128472a6e9c78dede5f5

                var alice = new Ecies {
                    PrivateKey = aliceKey, PublicKey = bobKey.CreatePublicKey(), NoKey = true
                };
                var bob = new Ecies {
                    PrivateKey = bobKey, PublicKey = aliceKey.CreatePublicKey(), NoKey = true
                };

                var ciphertext = alice.Encrypt(message);
                Assert.Equal(encrypted, ciphertext.ToHex());

                var decryptedtext = bob.DecryptToUtf8(ciphertext);
                Assert.Equal(message, decryptedtext);
            }

            {
                var encrypted = "12c732611c6917ab5c57a1926973bc44a1586e94a783f81d05ce72518d9b0a80e2e13c7f";
                // encrypted broken down:
                // priv.pubkey
                // ivbuf       12c732611c6917ab5c57a1926973bc44
                // encrypted   a1586e94a783f81d05ce72518d9b0a80
                // sig         e2e13c7f

                var alice = new Ecies {
                    PrivateKey = aliceKey, PublicKey = bobKey.CreatePublicKey(), NoKey = true, ShortTag = true
                };
                var bob = new Ecies {
                    PrivateKey = bobKey, PublicKey = aliceKey.CreatePublicKey(), NoKey = true, ShortTag = true
                };

                var ciphertext = alice.Encrypt(message);
                Assert.Equal(encrypted, ciphertext.ToHex());

                var decryptedtext = bob.DecryptToUtf8(ciphertext);
                Assert.Equal(message, decryptedtext);
            }
        }
 public DefaultSignatureProvider(string privateKey)
 {
     this.PrivateKeys = new PrivateKey[] { PrivateKey.FromWif(privateKey) };
 }
Esempio n. 20
0
 public void FromWifBad()
 {
     Assert.ThrowsException <ArgumentException>(() => PrivateKey.FromWif("74pxNKNpByQ2kMow4d9kF6Z77BYeKztQNLq3dSyU4ES1K5KLNiz"));
     Assert.ThrowsException <FormatException>(() => PrivateKey.FromWif("Kz3sAkMYRTwnXhi2UieoP4qKfMjpqYq7XWkqYR37pBgc3hqoimua"));
 }
Esempio n. 21
0
 public IPrivateKey FromWif(string wif) => PrivateKey.FromWif(wif);
Esempio n. 22
0
 public void ToPublicKey()
 {
     Assert.IsNotNull(PrivateKey.FromWif("Kz3sAkMYRTwnXhi2UieoP4qKfMjpqYq7XWkqYR37pBgc3hqoimuq").ToPublicKey());
 }