Exemple #1
0
        private void button1_Click(object sender, EventArgs e) //读取
        {
            textBox2.Text = "";
            Console.WriteLine("start get");

            string privateKeyStr = PrivateKey;
            //string privateKeyStr = "cUvazeu9ucqD4trygt8xMEQKZfR3SZ5BdiAWb3eEwbQ48iPwYKSB";
            BitcoinSecret  privateKey = new BitcoinSecret(privateKeyStr);
            Network        network    = privateKey.Network;
            PubKey         pubKey     = privateKey.PubKey;
            string         pubKeyStr  = pubKey.ToHex();
            KeyId          pkhash     = pubKey.Hash;
            string         pkhashStr  = pkhash.ToString();
            BitcoinAddress addres     = pkhash.GetAddress(network);
            string         address    = addres.ToString();
            string         networkStr = bsvConfiguration_class.testNetwork;
            string         uri        = bsvConfiguration_class.RestApiUri;

            //获取链上的交易历史
            Task <RestApiAddressHistoryTx[]> t = Task <RestApiAddressHistoryTx[]> .Run(() =>
            {
                RestApiAddressHistoryTx[] addrHistory = RestApi_class.getAddressHistory(uri, networkStr, address);
                return(addrHistory);
            });

            t.Wait();
            int num = t.Result.Length;

            Console.WriteLine("链上交易数目:" + num);
            //读取链上信息
            Task <RestApiTransaction[]> gettxs = null;

            if (num > 0)
            {
                string[] txHashs = new string[num];
                for (int i = 0; i < num; i++)
                {
                    txHashs[i] = t.Result[i].TxHash;
                }

                gettxs = Task <RestApiTransaction[]> .Run(() =>
                {
                    RestApiTransaction[] txs = RestApi_class.getTransactions(uri, networkStr, txHashs);
                    return(txs);
                });
            }

            for (int i = 0; i < num; i++)
            {
                RestApiTransaction tx = gettxs.Result[i];
                string             s  = RestApi_class.getOpReturnData(tx, bsvConfiguration_class.encoding);
                if (s != null)
                {
                    //解密
                    byte[]        encryptedBytes;
                    Base58Encoder base58Encoder = new Base58Encoder();
                    encryptedBytes = base58Encoder.DecodeData(s);
                    string data = AES_class.AesDecrypt(encryptedBytes, privateKeyStr);
                    textBox2.Text += data;
                    textBox2.Text += "\r\n";
                    textBox2.Text += System.Environment.NewLine;
                    textBox2.Text += "------------------------------------------------------------------------------------";
                    textBox2.Text += "\r\n";
                    textBox2.Text += System.Environment.NewLine;
                    Console.WriteLine("链上内容:" + s);
                }
            }
        }
Exemple #2
0
        //登录
        private void button1_Click(object sender, EventArgs e)
        {
            string user   = textBox1.Text;
            string pwd    = textBox2.Text;
            string AESkey = user + pwd;

            while (AESkey.Length < 32)
            {
                AESkey += "1";
            }
            //打开文件获取密文

            string c = null;

            try
            {
                c = File.ReadAllText(user);
            }
            catch (Exception ex)
            {
                MessageBox.Show("获取失败!请确认您是否已注册!\n" + ex.Message);
            }

            //对密文解密
            try
            {
                //string c = File.ReadAllText("privatekey.txt");
                byte[]        encryptedBytes;
                Base58Encoder base58Encoder = new Base58Encoder();
                encryptedBytes = base58Encoder.DecodeData(c);
                string plain = AES_class.AesDecrypt(encryptedBytes, AESkey);
                //确认身份
                int    n    = plain.Length;
                int    flag = 0;
                string pkey = null;
                for (int i = 0; i < 3; i++)
                {
                    if (plain[i] != '[')
                    {
                        flag = 1;
                    }
                }
                for (int i = n - 1; i > n - 4; i--)
                {
                    if (plain[i] != ']')
                    {
                        flag = 1;
                    }
                }
                if (flag == 0)  //身份正确
                {
                    for (int i = 3; i < n - 3; i++)
                    {
                        pkey += plain[i];
                    }
                    //Console.WriteLine("私钥:" + pkey);
                    this.Hide();
                    Form1 ff = new Form1(pkey);
                    ff.ShowDialog();
                }
                else
                {
                    MessageBox.Show("登录失败!请确认用户名密码输入正确!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("登录失败!请确认用户名密码输入正确!\n" + ex.Message);
            }
        }