public static byte[] Sign(this ISignable signable, Account account) { using (account.Decrypt()) { return signable.Sign(account.PrivateKey, account.PublicKey.EncodePoint(false).Skip(1).ToArray()); } }
private void OnCreateAccount(WalletAccount account) { byte[] decryptedPrivateKey = new byte[96]; Buffer.BlockCopy(account.PublicKey.EncodePoint(false), 1, decryptedPrivateKey, 0, 64); using (account.Decrypt()) { Buffer.BlockCopy(account.PrivateKey, 0, decryptedPrivateKey, 64, 32); } byte[] encryptedPrivateKey = EncryptPrivateKey(decryptedPrivateKey); Array.Clear(decryptedPrivateKey, 0, decryptedPrivateKey.Length); using (WalletDataContext ctx = new WalletDataContext(DbPath)) { Account db_account = ctx.Accounts.FirstOrDefault(p => p.PublicKeyHash.SequenceEqual(account.PublicKeyHash.ToArray())); if (db_account == null) { db_account = ctx.Accounts.Add(new Account { PrivateKeyEncrypted = encryptedPrivateKey, PublicKeyHash = account.PublicKeyHash.ToArray() }).Entity; } else { db_account.PrivateKeyEncrypted = encryptedPrivateKey; } ctx.SaveChanges(); } }
public override WalletAccount CreateAccount(byte[] privateKey) { WalletAccount account = base.CreateAccount(privateKey); OnCreateAccount(account); AddContract(WalletContract.CreateSignatureContract(account.PublicKey)); return(account); }
public override WalletAccount CreateAccount() { WalletAccount account = base.CreateAccount(); OnCreateAccount(account); AddContract(SignatureContract.Create(account.PublicKey)); return(account); }
public override WalletAccount Import(string wif) { WalletAccount account = base.Import(wif); OnCreateAccount(account); AddContract(SignatureContract.Create(account.PublicKey)); return(account); }
public Account CreateAccount() { using (CngKey key = CngKey.Create(CngAlgorithm.ECDsaP256, null, new CngKeyCreationParameters { ExportPolicy = CngExportPolicies.AllowPlaintextArchiving })) { byte[] privateKey = key.Export(CngKeyBlobFormat.EccPrivateBlob); Account account = new Account(privateKey); SaveAccount(account); Array.Clear(privateKey, 0, privateKey.Length); return account; } }
public ViewPrivateKeyDialog(Account account, UInt160 scriptHash) { InitializeComponent(); textBox3.Text = Wallet.ToAddress(scriptHash); textBox4.Text = account.PublicKey.EncodePoint(true).ToHexString(); using (account.Decrypt()) { textBox1.Text = account.PrivateKey.ToHexString(); } textBox2.Text = account.Export(); }
private WAccount GetAccountInternal(byte[] encryptedPrivateKey) { if (encryptedPrivateKey?.Length != 96) { return(null); } byte[] decryptedPrivateKey = DecryptPrivateKey(encryptedPrivateKey); WAccount account = new WAccount(decryptedPrivateKey); Array.Clear(decryptedPrivateKey, 0, decryptedPrivateKey.Length); return(account); }
protected override IEnumerable <WalletAccount> LoadAccounts() { using (WalletDataContext ctx = new WalletDataContext(DbPath)) { foreach (byte[] encryptedPrivateKey in ctx.Accounts.Select(p => p.PrivateKeyEncrypted)) { byte[] decryptedPrivateKey = DecryptPrivateKey(encryptedPrivateKey); WalletAccount account = new WalletAccount(decryptedPrivateKey); Array.Clear(decryptedPrivateKey, 0, decryptedPrivateKey.Length); yield return(account); } } }
protected override IEnumerable<WalletAccount> LoadAccounts() { using (WalletDataContext ctx = new WalletDataContext(DbPath)) { foreach (byte[] encryptedPrivateKey in ctx.Accounts.Select(p => p.PrivateKeyEncrypted)) { byte[] decryptedPrivateKey = DecryptPrivateKey(encryptedPrivateKey); WalletAccount account = new WalletAccount(decryptedPrivateKey); Array.Clear(decryptedPrivateKey, 0, decryptedPrivateKey.Length); yield return account; } } }
public Account Import(string wif) { if (wif == null) throw new ArgumentNullException(); byte[] data = Base58.Decode(wif); if (data.Length != 38 || data[0] != 0x80 || data[33] != 0x01) throw new FormatException(); byte[] checksum = data.Sha256(0, data.Length - 4).Sha256(); if (!data.Skip(data.Length - 4).SequenceEqual(checksum.Take(4))) throw new FormatException(); byte[] privateKey = new byte[32]; Buffer.BlockCopy(data, 1, privateKey, 0, privateKey.Length); Account account = new Account(privateKey); SaveAccount(account); Array.Clear(privateKey, 0, privateKey.Length); Array.Clear(data, 0, data.Length); return account; }
protected abstract void SaveAccount(Account account);
public CertificateRequestDialog(Account account) { InitializeComponent(); this.account = account; }
private WAccount GetAccountInternal(byte[] encryptedPrivateKey) { if (encryptedPrivateKey?.Length != 96) return null; byte[] decryptedPrivateKey = DecryptPrivateKey(encryptedPrivateKey); WAccount account = new WAccount(decryptedPrivateKey); Array.Clear(decryptedPrivateKey, 0, decryptedPrivateKey.Length); return account; }