private static void GenerateAddress(int threadId, bool caseSensitive, string outputFilePath) { var keyGenerator = new KeyGenerator(400); int loopCounter = 0; ulong outputCounter = 0; double runTimeSeconds = 0.0; StringComparison comparisonType = caseSensitive ? StringComparison.InvariantCulture : StringComparison.InvariantCultureIgnoreCase; DateTime start = DateTime.Now; using (StreamWriter fileWriter = File.AppendText(outputFilePath)) { while (!_terminate) { EthECKey ecKey = keyGenerator.GenerateKey(); string beginning = keyGenerator.GetStartLowerCase(ecKey, _maxPrefixLength); foreach (string prefix in _prefixes) { if (beginning.StartsWith(prefix, StringComparison.InvariantCultureIgnoreCase)) { string address = ecKey.GetPublicAddress(); if (address.StartsWith(prefix, comparisonType)) { string privateKey = ecKey.GetPrivateKey(); fileWriter.WriteLine($"{address} - {privateKey}"); fileWriter.Flush(); Console.Beep(); Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine($"MATCH: {address} {privateKey}"); Console.ResetColor(); Console.Title = "MATCH!"; } } } if (++loopCounter == OUTPUT_INTERVAL) { loopCounter = 0; outputCounter++; TimeSpan duration = DateTime.Now - start; runTimeSeconds += duration.TotalSeconds; double avgSeconds = runTimeSeconds / outputCounter; Console.WriteLine($"{OUTPUT_INTERVAL} more keys checked on thread {threadId} in ~{(int)duration.TotalSeconds}sec (avg. {avgSeconds:0.00}sec)"); Console.WriteLine($"Last: {ecKey.GetPublicAddress()} ({ecKey.GetPrivateKey()})"); Console.WriteLine(new string('=', 80)); start = DateTime.Now; } } } }
private void Initialise(EthECKey key) { PrivateKey = key.GetPrivateKey(); Address = key.GetPublicAddress(); PublicKey = key.GetPubKey().ToHex(); InitialiseDefaultTransactionManager(); }
private void Start() { //PlayerPrefs.DeleteAll(); SaveData = JsonUtility.FromJson <SaveDataModel>(PlayerPrefs.GetString("SaveData")); if (SaveData == null) { SaveData = new SaveDataModel(); } if (string.IsNullOrEmpty(SaveData.PrivateKey)) { EthECKey ecKey = EthECKey.GenerateKey(); SaveData.PrivateKey = ecKey.GetPrivateKey().Substring(2); SaveData.Address = ecKey.GetPublicAddress().ToLower().Trim(); } else { EthECKey ecKey = new EthECKey(SaveData.PrivateKey); SaveData.Address = ecKey.GetPublicAddress().ToLower().Trim(); } if (SaveData.Balance <= (decimal)1) { ETHManager.Instance.RopstenFauset(SaveData.Address, (arg0) => { }); } Save(); GetBalance(); }
static void Main() { //var privKey = EthECKey.GenerateKey(); var privKey = new EthECKey("97ddae0f3a25b92268175400149d65d6887b9cefaf28ea2c078e05cdc15a3c0a"); byte[] pubKeyCompressed = new ECKey(privKey.GetPrivateKeyAsBytes(), true).GetPubKey(true); Console.WriteLine("Private key: {0}", privKey.GetPrivateKey().Substring(4)); Console.WriteLine("Public key: {0}", privKey.GetPubKey().ToHex().Substring(2)); Console.WriteLine("Public key (compressed): {0}", pubKeyCompressed.ToHex()); Console.WriteLine(); string msg = "Message for signing"; byte[] msgBytes = Encoding.UTF8.GetBytes(msg); byte[] msgHash = new Sha3Keccack().CalculateHash(msgBytes); var signature = privKey.SignAndCalculateV(msgHash); Console.WriteLine("Msg: {0}", msg); Console.WriteLine("Msg hash: {0}", msgHash.ToHex()); Console.WriteLine("Signature: [v = {0}, r = {1}, s = {2}]", signature.V[0] - 27, signature.R.ToHex(), signature.S.ToHex()); Console.WriteLine(); var pubKeyRecovered = EthECKey.RecoverFromSignature(signature, msgHash); Console.WriteLine("Recovered pubKey: {0}", pubKeyRecovered.GetPubKey().ToHex().Substring(2)); bool validSig = pubKeyRecovered.Verify(msgHash, signature); Console.WriteLine("Signature valid? {0}", validSig); }
/// <summary> /// Loads the wallet from the filesystem /// </summary> /// <param name="json">The json string representing the encrypted wallet</param> /// <param name="passKey">The pass key to unlock the wallet</param> private void LoadFromKeyStore(string json, string passKey) { var keyStoreService = new KeyStoreService(); var privateKey = keyStoreService.DecryptKeyStoreFromJson(passKey, json); var key = new EthECKey(privateKey, true); TransactionManager = new AccountSignerTransactionManager(null, key.GetPrivateKey(), ChainId); }
public void CreatePkey() { EthECKey ecKey = EthECKey.GenerateKey(); accountPrivateKey = ecKey.GetPrivateKey(); CopyMainPrivateKey(); AfterEnterPkey(); }
// ------------------------------------------- /* * Display messages on screen and buttons on screen */ void OnGUI() { GUI.skin = SkinUI; float fontSize = 1.2f * 15; // BUTTON CLEAR LOG float yGlobalPosition = 10; if (GUI.Button(new Rect(new Vector2(10, yGlobalPosition), new Vector2(Screen.width - 20, 2 * fontSize)), "Clear Log")) { m_activateTextArea = false; m_displayMessages.Clear(); } yGlobalPosition += 2.2f * fontSize; // GENERATE NEW KEY if (GUI.Button(new Rect(new Vector2(10, yGlobalPosition), new Vector2(Screen.width - 20, 4 * fontSize)), "Create free new address on ++" + EthereumController.Instance.NetworkAPI + "++ Network")) { #if ENABLE_ETHEREUM EthECKey ecKey = EthECKey.GenerateKey(); string privateKey = ecKey.GetPrivateKey(); AddLog("+++GENERATING KEY FOR NETWORK[" + EthereumController.Instance.NetworkAPI + "]+++"); AddLog("++++KEY GENERATED++++"); AddLog("PRIVATE KEY:"); AddLog("" + privateKey); AddLog("PUBLIC KEY:"); AddLog("" + ecKey.GetPublicAddress()); #endif } yGlobalPosition += 4.2f * fontSize; // LOG DISPLAY GUI.Label(new Rect(0, yGlobalPosition, Screen.width - 20, fontSize), "**PROGRAM LOG**"); yGlobalPosition += 1.2f * fontSize; int linesTextArea = 10; if (m_activateTextArea) { linesTextArea = 10; } else { linesTextArea = 2; } float finalHeighArea = linesTextArea * fontSize; m_scrollPosition = GUI.BeginScrollView(new Rect(10, yGlobalPosition, Screen.width - 20, Screen.height - yGlobalPosition), m_scrollPosition, new Rect(0, 0, 200, m_displayMessages.Count * finalHeighArea)); float yPosition = 0; for (int i = 0; i < m_displayMessages.Count; i++) { string message = m_displayMessages[i]; GUI.TextArea(new Rect(0, yPosition, Screen.width, finalHeighArea), message); yPosition += finalHeighArea; } GUI.EndScrollView(); }
public IKeySecret LoadKeySecret(string privateKey) { var key = new EthECKey(privateKey); return(new EthKeySecret() { PrivateKey = key.GetPrivateKey(), PublicAddress = key.GetPublicAddress() }); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); EthECKey keyPair = EthECKey.GenerateKey(); Console.WriteLine("private key =>" + keyPair.GetPrivateKey()); Console.WriteLine("public key=>" + keyPair.GetPubKey().ToHex()); Console.WriteLine("address=>" + keyPair.GetPublicAddress()); var wordlist = "brass bus same payment express already energy direct type have venture afraid"; var privateKey = keyPair.GetPrivateKey(); var addresss = keyPair.GetPublicAddress(); Web3 web3 = new Web3("http://localhost:7545"); var nonce = web3.Eth.Transactions.GetTransactionCount.SendRequestAsync(addresss).GetAwaiter().GetResult(); Console.ReadLine(); }
public static void ImportWallet(string accountName, string password, string encryptedJson) { // Use key store service to re-generate the key var service = new KeyStoreService(); byte[] bytes = service.DecryptKeyStoreFromJson(password, encryptedJson); var ecKey = new EthECKey(bytes, true); // Created the wallet with given info AddWallet(accountName, ecKey.GetPublicAddress(), encryptedJson, ecKey.GetPrivateKey()); }
public void SharedSecretGenerationBasedOnEthKeyImportTest() { EthECKey ecKey1 = EthECKey.GenerateKey(); EthECKey ecKey2 = EthECKey.GenerateKey(); X25519Key alice = X25519Key.ImportKey(ecKey1.GetPrivateKey()); X25519Key bob = X25519Key.ImportKey(ecKey2.GetPrivateKey()); var shared1 = alice.GenerateSharedSecretHex(bob.PublicKey); var shared2 = bob.GenerateSharedSecretHex(alice.PublicKey); Assert.Equal(shared1, shared2); }
public void SharedSecretECDHImportTest() { EthECKey ecKey1 = EthECKey.GenerateKey(); EthECKey ecKey2 = EthECKey.GenerateKey(); ECDH_Key alice = ECDH_Key.ImportKey(ecKey1.GetPrivateKey()); ECDH_Key bob = ECDH_Key.ImportKey(ecKey2.GetPrivateKey()); var ecPubKey1 = ecKey1.GetPubKey().ToHex(true); var ecPubKey2 = ecKey2.GetPubKey().ToHex(true); var shared1 = alice.GenerateSharedSecretHex(bob.PublicKey); var shared2 = bob.GenerateSharedSecretHex(alice.PublicKey); Assert.Equal(shared1, shared2); }
private string GetPrivateKeyFromKeystore(string pass) { if (keystoreJSON == null || keystoreJSON == "" || pass == null || pass == "") { return(""); } byte[] b = m_keystoreService.DecryptKeyStoreFromJson(pass, keystoreJSON); EthECKey myKey = new EthECKey(b, true); if (myKey.GetPublicAddress() != accountAddress) { return(""); } return(myKey.GetPrivateKey()); }
public void SharedSecretGenerationBasedOnEthKeyImportTest() { EthECKey ecKey1 = EthECKey.GenerateKey(); EthECKey ecKey2 = EthECKey.GenerateKey(); X25519Key alice = X25519Key.ImportKey(ecKey1.GetPrivateKey()); X25519Key bob = X25519Key.ImportKey(ecKey2.GetPrivateKey()); var s1 = alice.GenerateSharedSecretHex(ecKey2.GetPubKey().ToHex(true)); var s2 = bob.GenerateSharedSecretHex(ecKey1.GetPubKey().ToHex(true)); var shared1 = alice.GenerateSharedSecretHex(bob.PublicKey); var shared2 = bob.GenerateSharedSecretHex(alice.PublicKey); Assert.Equal(shared1, shared2); testOutputHelper.WriteLine(shared1); testOutputHelper.WriteLine(shared2); }
public void WordTest() { //1、通过助记词 得到私钥 Mnemonic mnemo = new Mnemonic("累 妙 清 董 贮 程 异 瞧 敲 发 拍 虾", Wordlist.ChineseSimplified); ExtKey hdRoot = mnemo.DeriveExtKey("123456"); var privateKey = hdRoot.PrivateKey.ToBytes(); //字节--》对应不同私钥体系 var ethKey = new EthECKey(privateKey, true); var hdEthPrivateKey = ethKey.GetPrivateKey(); //得到hdEthPrivateKey Mnemonic tempMnemonic = new Mnemonic("累 妙 清 董 贮 程 异 瞧 敲 发 拍 虾", Wordlist.ChineseSimplified); string Seed = tempMnemonic.DeriveSeed("123456").ToHex(); //2、通过计算得到种子,获得私钥 var masterKey = new ExtKey(Seed); //var masterKeyString = masterKey.PrivateKey.GetBitcoinSecret(Network.Main); var tempEthKey = new EthECKey(masterKey.PrivateKey.ToBytes(), true); var tempPrivateKey = tempEthKey.GetPrivateKey(); Assert.Equal(hdEthPrivateKey, tempPrivateKey); }
public Account CreateAccount(string password, EthECKey key, string path) { if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } //Create a store service, to encrypt and save the file using the web3 standard var service = new KeyStoreService(); var encryptedKey = service.EncryptAndGenerateDefaultKeyStoreAsJson(password, key.GetPrivateKeyAsBytes(), key.GetPublicAddress()); var fileName = service.GenerateUTCFileName(key.GetPublicAddress()); //save the File using (var newfile = File.CreateText(Path.Combine(path, fileName))) { newfile.Write(encryptedKey); newfile.Flush(); } return(new Account(key.GetPrivateKey())); }
private void Initialise(EthECKey key) { PrivateKey = key.GetPrivateKey(); PublicKey = key.GetPubKey().ToHex(); Address = Bech32.Encode("io", Hash.Hash160B(key.GetPubKey().Slice(1))); }