//This is standard signing, unlike message compact signing with formating. static void TxnSign() { Console.WriteLine("Enter private key: (Use hex type"); Console.WriteLine(); string pk = Console.ReadLine(); Console.WriteLine(); ECLibrary.Signer.EthECKey key = new ECLibrary.Signer.EthECKey(pk.HexToByteArray(), true); Console.WriteLine("Enter local path to file: "); Console.WriteLine(); var message = Console.ReadLine(); Console.WriteLine(); byte[] msg = FileToBytes(message); using (var sha = new SHA256Managed()) { var sig = key.Sign(sha.ComputeHash(msg)); var der = sig.ToDER(); Console.WriteLine(der.ToHex()); } Console.ReadLine(); }
static void Main(string[] args) { try { Console.WriteLine("Enter developer private key: (Use hex type"); Console.WriteLine(); string pk = Console.ReadLine(); Console.WriteLine(); ECLibrary.Signer.EthECKey key = new ECLibrary.Signer.EthECKey(pk.HexToByteArray(), true); string PubKey = key.GetPubKey().ToHex(); var sha = SHA256Managed.Create(); RIPEMD160Managed rIPEMD160Managed = new RIPEMD160Managed(); var ripemd = rIPEMD160Managed.ComputeHash(sha.ComputeHash(key.GetPubKey())); string linked = ""; Console.Clear(); Console.WriteLine("Enter Task/TxnType: (//0 MSG//1 ARTICLE//2 DOWNLOAD//3 STATUS UPDATE)"); Console.WriteLine(); string type = Console.ReadLine(); Console.WriteLine(); int stype = Convert.ToInt32(type); if (stype \\ 3) return; string message = ""; var uri = "https://bitfi.dev/NoxMessages/API/PostMsg.aspx?TxnType="; uri = uri + stype.ToString(); if (stype == 0) { Console.WriteLine("Enter linked message txn id: (leave blank if starting discussion)"); Console.WriteLine(); linked = Console.ReadLine(); Console.WriteLine(); } if (stype == 1) { string ArticleTitle = ""; string ArticleSubTitle = ""; string ArticleDescription = ""; string ArticleTag = ""; Console.WriteLine("Enter Article category (most should use type 0 for All Articles category)"); Console.WriteLine(); string category = Console.ReadLine(); Console.WriteLine(); if (string.IsNullOrEmpty(category)) category = "0"; uri = uri + "&ArticleCategory=" + category; Console.WriteLine("Enter ArticleTitle:"); Console.WriteLine(); ArticleTitle = Console.ReadLine(); Console.WriteLine(); uri = uri + "&ArticleTitle=" + ArticleTitle; Console.WriteLine("Enter ArticleSubTitle:"); Console.WriteLine(); ArticleSubTitle = Console.ReadLine(); Console.WriteLine(); uri = uri + "&ArticleSubTitle=" + ArticleSubTitle; Console.WriteLine("Enter ArticleDescription:"); Console.WriteLine(); ArticleDescription = Console.ReadLine(); Console.WriteLine(); uri = uri + "&ArticleDescription=" + ArticleDescription; Console.WriteLine("Enter ArticleTag:"); Console.WriteLine(); ArticleTag = Console.ReadLine(); Console.WriteLine(); uri = uri + "&ArticleTag=" + ArticleTag; Console.WriteLine("Enter article content: (Base64 String)"); Console.WriteLine(); message = Console.ReadLine(); Console.WriteLine(); byte[] msg = Convert.FromBase64String(message); message = System.Text.Encoding.UTF8.GetString(msg); } if (stype == 2) { Console.WriteLine("Enter Download short name: "); Console.WriteLine(); string shortname = Console.ReadLine(); Console.WriteLine(); Console.WriteLine("Enter Download description: "); Console.WriteLine(); string description = Console.ReadLine(); Console.WriteLine(); Console.WriteLine("Enter Download URL: "); Console.WriteLine(); string download_url = Console.ReadLine(); Console.WriteLine(); Download_Page download_Page = new Download_Page(); download_Page.description = description; download_Page.download_url = download_url; download_Page.short_name = shortname; var settings = new JsonSerializerSettings(); settings.Formatting = Formatting.None; settings.StringEscapeHandling = StringEscapeHandling.Default; var str = JsonConvert.SerializeObject(download_Page, settings); message = str; } if (stype == 3) { Console.WriteLine("Enter TxnID for transaction to update: "); Console.WriteLine(); string txnidupdate = Console.ReadLine(); Console.WriteLine(); Console.WriteLine("Enter true/false value for list display: "); Console.WriteLine(); bool display = Convert.ToBoolean(Console.ReadLine()); Console.WriteLine(); Status_Update status_Update = new Status_Update(); status_Update.list_display = display; status_Update.txn_id = txnidupdate; var settings = new JsonSerializerSettings(); settings.Formatting = Formatting.None; settings.StringEscapeHandling = StringEscapeHandling.Default; var str = JsonConvert.SerializeObject(status_Update, settings); message = str; } bool success = true; if (stype == 0) { while (key != null && success == true) { Console.WriteLine("Enter Message: "); Console.WriteLine(); message = Console.ReadLine(); Console.WriteLine(); byte[] msgbts = System.Text.Encoding.UTF8.GetBytes(message); byte[] EncodedMsg = Util.NBitcoinUtils.CreateEncodedMessageD2(message); byte[] signaturebts = SignMsg(EncodedMsg, key.GetPrivateKeyAsBytes(), key.GetPubKey()); string Signature = Convert.ToBase64String(signaturebts); string rawtxn = BuildMsgTxn(ripemd.ToHex(), msgbts.ToHex(), Signature, linked); if (string.IsNullOrEmpty(linked)) { string[] decode = ReadMsgTxn(rawtxn); linked = decode[0]; } var resp = WebTests.POST(uri, rawtxn); success = resp.success; Console.WriteLine("Success: " + resp.success); if (!success) { Console.WriteLine(resp.error_message); Console.WriteLine(); Console.WriteLine("Any key to exit..."); } else { Console.WriteLine(); Console.WriteLine("Sent...contiune comments with txn: " + linked); } } } else { byte[] msgbts = System.Text.Encoding.UTF8.GetBytes(message); byte[] EncodedMsg = Util.NBitcoinUtils.CreateEncodedMessageD2(message); byte[] signaturebts = SignMsg(EncodedMsg, key.GetPrivateKeyAsBytes(), key.GetPubKey()); string Signature = Convert.ToBase64String(signaturebts); string rawtxn = BuildMsgTxn(ripemd.ToHex(), msgbts.ToHex(), Signature, linked); var resp = WebTests.POST(uri, rawtxn); Console.WriteLine("Success: " + resp.success); Console.WriteLine(resp.error_message); Console.WriteLine(); Console.WriteLine("Any key to exit..."); Console.ReadLine(); } } catch (Exception ex) { Console.WriteLine("ERROR: " + ex.Message); Console.WriteLine("Invalid information for building txn. Any key to exit..."); Console.ReadLine(); } }