示例#1
0
        public static MyWallet Load(string path, string password)
        {
            MyWallet wallet = new MyWallet();

            byte[] aes_key = Encoding.UTF8.GetBytes(password).Sha256().Sha256();
            byte[] aes_iv  = new byte[16];
            using (AesManaged aes = new AesManaged())
                using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
                {
                    fs.Read(aes_iv, 0, aes_iv.Length);
                    using (ICryptoTransform decryptor = aes.CreateDecryptor(aes_key, aes_iv))
                        using (CryptoStream cs = new CryptoStream(fs, decryptor, CryptoStreamMode.Read))
                            using (BinaryReader reader = new BinaryReader(cs))
                            {
                                int count = (int)reader.ReadVarInt();
                                for (int i = 0; i < count; i++)
                                {
                                    byte[]  privateKey    = reader.ReadBytes(32);
                                    bool    compressed    = reader.ReadBoolean();
                                    ECPoint publicKey     = ECCurve.Secp256k1.G * privateKey;
                                    UInt160 publicKeyHash = publicKey.EncodePoint(compressed).ToScriptHash();
                                    wallet.accounts.Add(new WalletEntry(privateKey, publicKey, publicKeyHash, compressed));
                                }
                            }
                }
            Array.Clear(aes_key, 0, aes_key.Length);
            return(wallet);
        }
示例#2
0
 public static MyWallet Load(string path, string password)
 {
     MyWallet wallet = new MyWallet();
     byte[] aes_key = Encoding.UTF8.GetBytes(password).Sha256().Sha256();
     byte[] aes_iv = new byte[16];
     using (AesManaged aes = new AesManaged())
     using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
     {
         fs.Read(aes_iv, 0, aes_iv.Length);
         using (ICryptoTransform decryptor = aes.CreateDecryptor(aes_key, aes_iv))
         using (CryptoStream cs = new CryptoStream(fs, decryptor, CryptoStreamMode.Read))
         using (BinaryReader reader = new BinaryReader(cs))
         {
             int count = (int)reader.ReadVarInt();
             for (int i = 0; i < count; i++)
             {
                 byte[] privateKey = reader.ReadBytes(32);
                 bool compressed = reader.ReadBoolean();
                 ECPoint publicKey = ECCurve.Secp256k1.G * privateKey;
                 UInt160 publicKeyHash = publicKey.EncodePoint(compressed).ToScriptHash();
                 wallet.accounts.Add(new WalletEntry(privateKey, publicKey, publicKeyHash, compressed));
             }
         }
     }
     Array.Clear(aes_key, 0, aes_key.Length);
     return wallet;
 }
示例#3
0
        public static MyWallet Create()
        {
            MyWallet wallet = new MyWallet();

            wallet.CreateEntry();
            return(wallet);
        }
示例#4
0
 private void OpenWallet(MyWallet wallet)
 {
     this.wallet = wallet;
     listView1.Items.Clear();
     listView1.Items.AddRange(wallet.GetAddresses().Select(p => new ListViewItem(new[] { p, "" }) { Name = p }).ToArray());
     RefreshWallet();
     创建新地址NToolStripMenuItem.Enabled = true;
     导入私钥IToolStripMenuItem.Enabled = true;
     button1.Enabled = true;
 }
示例#5
0
 private void OpenWallet(MyWallet wallet)
 {
     this.wallet = wallet;
     listView1.Items.Clear();
     listView1.Items.AddRange(wallet.GetAddresses().Select(p => new ListViewItem(new[] { p, "" })
     {
         Name = p
     }).ToArray());
     RefreshWallet();
     创建新地址NToolStripMenuItem.Enabled = true;
     导入私钥IToolStripMenuItem.Enabled  = true;
     button1.Enabled = true;
 }
示例#6
0
 private void 新建钱包NToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (CreateWalletDialog dialog = new CreateWalletDialog())
     {
         if (dialog.ShowDialog() != DialogResult.OK)
         {
             return;
         }
         MyWallet wallet = MyWallet.Create();
         wallet.Save(dialog.WalletPath, dialog.Password);
         wallet_path = dialog.WalletPath;
         password    = dialog.Password;
         OpenWallet(wallet);
     }
 }
示例#7
0
 private void 打开钱包OToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (OpenWalletDialog dialog = new OpenWalletDialog())
     {
         if (dialog.ShowDialog() != DialogResult.OK)
         {
             return;
         }
         MyWallet wallet;
         try
         {
             wallet = MyWallet.Load(dialog.WalletPath, dialog.Password);
         }
         catch
         {
             MessageBox.Show("密码错误");
             return;
         }
         wallet_path = dialog.WalletPath;
         password    = dialog.Password;
         OpenWallet(wallet);
     }
 }
示例#8
0
 public static MyWallet Create()
 {
     MyWallet wallet = new MyWallet();
     wallet.CreateEntry();
     return wallet;
 }
示例#9
0
 private void 打开钱包OToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (OpenWalletDialog dialog = new OpenWalletDialog())
     {
         if (dialog.ShowDialog() != DialogResult.OK) return;
         MyWallet wallet;
         try
         {
             wallet = MyWallet.Load(dialog.WalletPath, dialog.Password);
         }
         catch
         {
             MessageBox.Show("密码错误");
             return;
         }
         wallet_path = dialog.WalletPath;
         password = dialog.Password;
         OpenWallet(wallet);
     }
 }