private void ButtonWordsToKeys_Click(object sender, RoutedEventArgs e) { try { var words = txtWords.Text; var mnemonic = new MnemonicConverter(); var keys = mnemonic.WordsToKeys(words); txtKeys.Text = keys.ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); txtKeys.Text = string.Empty; } }
static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine(WriteHelp()); return; } string sf = string.Empty; string s = string.Empty; string wf = string.Empty; string w = string.Empty; string mode = string.Empty; string resultSecret = string.Empty; string resultWords = string.Empty; foreach (string a in args) { var parts = a.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length > 1) { if (string.Compare("-m", parts[0]) == 0) { mode = parts[1]; if (string.Compare(mode, "s2w") != 0 && string.Compare(mode, "w2s") != 0) { Console.WriteLine("invalid -m parameter, please use 's2w' or 'w2s'"); return; } } else if (string.Compare("-sf", parts[0]) == 0) { sf = parts[1]; if (string.IsNullOrEmpty(sf)) { Console.WriteLine("invalid -sf parameter"); return; } } else if (string.Compare("-wf", parts[0]) == 0) { wf = parts[1]; if (string.IsNullOrEmpty(wf)) { Console.WriteLine("invalid -wf parameter"); return; } } else if (string.Compare("-s", parts[0]) == 0) { s = parts[1]; if (string.IsNullOrEmpty(s)) { Console.WriteLine("invalid -s parameter"); return; } } else if (string.Compare("-w", parts[0]) == 0) { w = parts[1]; if (string.IsNullOrEmpty(w)) { Console.WriteLine("invalid -w parameter"); return; } } } } if (mode == "s2w") { if (!string.IsNullOrEmpty(sf)) { s = System.IO.File.ReadAllText(sf); } if (string.IsNullOrEmpty(s)) { Console.WriteLine("no secret specified"); return; } var key = Storage.ReconstructKeys(s); MnemonicConverter mnemonicConverter = new MnemonicConverter(); resultWords = mnemonicConverter.KeysToWords(key); if (!string.IsNullOrEmpty(wf)) { System.IO.File.WriteAllText(wf, resultWords); } else { Console.WriteLine(resultWords); } } else if (mode == "w2s") { if (!string.IsNullOrEmpty(wf)) { w = System.IO.File.ReadAllText(wf); } if (string.IsNullOrEmpty(w)) { Console.WriteLine("no words specified"); return; } MnemonicConverter mnemonicConverter = new MnemonicConverter(); var key = mnemonicConverter.WordsToKeys(w); resultSecret = Storage.ConstructKeys(key, false); if (!string.IsNullOrEmpty(sf)) { System.IO.File.WriteAllText(sf, resultSecret); } else { Console.WriteLine(resultSecret); } } }
public void TestWordsToKeys() { var newKeys = mnemonic.WordsToKeys(words); Assert.AreEqual(newKeys, keys); }