/// <summary> /// Load account from "key.txt" file placed in the root exe directory. Doesnt work in WABS /// </summary> /// <param name="password">Passwotd to decrypt the loaded private key</param> /// <param name="filename">Filename with the key. Default name is dogekey.txt</param> /// <returns></returns> public async Task <bool> LoadAccount(string password, string filename = "dogekey.txt") { if (FileHelpers.IsFileExists(filename)) { try { var k = FileHelpers.ReadTextFromFile(filename); var kdto = JsonConvert.DeserializeObject <KeyDto>(k); AccountKey = new EncryptionKey(kdto.Key, fromDb: true); AccountKey.LoadPassword(password); AccountKey.IsEncrypted = true; Address = kdto.Address; Secret = new BitcoinSecret(AccountKey.GetEncryptedKey(), DogeTransactionHelpers.Network); BAddress = Secret.GetAddress(ScriptPubKeyType.Legacy); await StartRefreshingData(); return(true); } catch { throw new Exception("Cannot deserialize key from file. Please check file key.txt or delete it for create new address!"); } } else { await CreateNewAccount(password); } return(false); }
public async Task LoadPrivateKeyWithPassCorrectTest() { var ekey = new EncryptionKey(FakeDataGenerator.DefaultDto.BasicEncryptedMessage, "", true); ekey.LoadPassword(FakeDataGenerator.DefaultDto.BasicPassword); var key = ekey.GetEncryptedKey(); Assert.Equal(FakeDataGenerator.DefaultDto.BasicMessage, key); }