public static UserWallet Create(string path, SecureString password) { UserWallet wallet = new UserWallet(path, password, true); wallet.CreateKey(); return(wallet); }
public static UserWallet Create(string path, string password) { UserWallet wallet = new UserWallet(path, password, true); wallet.CreateAccount(); return(wallet); }
public static UserWallet CreateDatabase(string path, string password) { using (WalletDataContext ctx = new WalletDataContext(path)) using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider()) { byte[] passwordKey = password.ToAesKey(); byte[] masterKey = new byte[32]; byte[] iv = new byte[16]; rng.GetNonZeroBytes(masterKey); rng.GetNonZeroBytes(iv); masterKey.AesEncrypt(passwordKey, iv); Array.Clear(passwordKey, 0, passwordKey.Length); ctx.Database.EnsureDeleted(); ctx.Database.EnsureCreated(); ctx.Keys.Add(new Key { Name = Key.MasterKey, Value = masterKey }); ctx.Keys.Add(new Key { Name = Key.IV, Value = iv }); ctx.SaveChanges(); } UserWallet wallet = OpenDatabase(path, password); wallet.CreateAccount(); return(wallet); }