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); }
private void btnOpenWallet_Click(object sender, EventArgs e) { try { //var sprivKey = EthECKey.GenerateKey(); //Console.Write("Private Key: "); var privKey = new EthECKey(txtOpenWalletPK.Text); byte[] pubKeyCompressed = new ECKey(privKey.GetPrivateKeyAsBytes(), true).GetPubKey(true); byte[] pubKeyShaRIPE = RipeMD160(pubKeyCompressed); //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("Public key (RIPEMD160): {0}", pubKeyShaRIPE.ToHex()); txtOpenWallet.Text = $"Private Key:\n{txtOpenWalletPK.Text}\nExtracted Public Key:\n{pubKeyCompressed.ToHex()} \nAddress:\n{pubKeyShaRIPE.ToHex()}"; TransactionWallet.addressSession = pubKeyShaRIPE.ToHex(); TransactionWallet.pubKeySession = pubKeyCompressed.ToHex(); MainForm.LabelTextAddress = pubKeyShaRIPE.ToHex(); SendToServerGetBalance(pubKeyShaRIPE.ToHex()); } catch (Exception fuku) { txtOpenWallet.Text = fuku.ToString(); } }
private void btnGenWallet_Click(object sender, EventArgs e) { var sprivKey = EthECKey.GenerateKey(); try { //var sprivKey = EthECKey.GenerateKey(); //Console.Write("Private Key: "); //string privxKey = Console.ReadLine(); var privKey = new EthECKey(sprivKey.GetPrivateKeyAsBytes().ToHex()); byte[] pubKeyCompressed = new ECKey(privKey.GetPrivateKeyAsBytes(), true).GetPubKey(true); byte[] pubKeyShaRIPE = RipeMD160(pubKeyCompressed); //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("Public key (RIPEMD160): {0}", pubKeyShaRIPE.ToHex()); //txtGenWallet.Text = sprivKey.GetPrivateKeyAsBytes().ToHex(); txtGenWallet.Text = $"Generated Private Key:\n{sprivKey.GetPrivateKeyAsBytes().ToHex()}\nExtracted Public Key:\n{pubKeyCompressed.ToHex()} \nAddress:\n{pubKeyShaRIPE.ToHex()}"; string data = $"%NEWWALLET%{pubKeyShaRIPE.ToHex()}"; frmMain.SendToServer(data); TransactionWallet.addressSession = pubKeyShaRIPE.ToHex(); TransactionWallet.pubKeySession = pubKeyCompressed.ToHex(); TransactionWallet.privKeySession = sprivKey.GetPrivateKeyAsBytes().ToHex(); SendToServerGetBalance(pubKeyShaRIPE.ToHex()); MainForm.LabelTextAddress = pubKeyShaRIPE.ToHex(); //((Label)frmMain.Controls["lblAccBalance"]).Text = "test"; //transWal.AddLog(sprivKey.GetPrivateKeyAsBytes().ToHex()); } catch (Exception error) { txtGenWallet.Text = error.ToString(); } }