// версия+информация private async Task UpdateSelf(string size_str, byte[] signature, IPEndPoint source, string new_version) { try { window.WriteLine("Client pending: " + size_str); window.WriteLine("nv: " + new_version); int size = Convert.ToInt32(size_str); byte[] buffer = await filetransfering.TcpDataGet(source, size); byte[] hash = cryptography.GetSHA256Hash(buffer); window.WriteLine("Client got: " + buffer.Length + " bytes"); TwoBytesArrays temp = new TwoBytesArrays(); temp = ByteArrayCut(buffer, version_size); string version = string.Empty; version = BytesToOperation(temp.part1); window.WriteLine("Version " + version + " ready"); window.WriteLine("Client: " + temp.part1.Length + " + " + temp.part2.Length + " = " + (temp.part1.Length + temp.part2.Length)); window.WriteLine("Siganture: " + cryptography.HashToString(signature)); window.WriteLine("Hash to check: " + cryptography.HashToString(hash)); // hash(version[15] + hash(row_data)[64]); window.WriteLine("exe hash: " + cryptography.HashToString(cryptography.GetSHA256Hash(temp.part2))); if (cryptography.VerifySign(hash, signature, Information.admin_public_key)) { window.WriteLine("Update to version: " + version + " started"); update_data = temp.part2; window.WriteLine("Update to : " + update_data.Length); window.ShowUpdateAvailable(version, update_data); } else { window.WriteLine("Wrong signature"); } } catch (Exception e) { window.WriteLine(e.ToString()); } }
public bool Self_verify() { return(cryptography.VerifySign(signed_hash, signature, admin_public_key)); }
public Transaction ParseTMessage(byte[] data) { Transaction result = new Transaction(); try { byte[] result_data = new byte[0]; byte[] signature = new byte[0]; string operations = string.Empty; string tmp = string.Empty; string[] tmp_list = new string[0]; byte[] body_data = new byte[0]; int info = 0; int bd_length = 0; TwoBytesArrays temp = new TwoBytesArrays(); temp = ByteArrayCut(data, Transactions.size_header); tmp = BytesToOperation(temp.part1); tmp_list = tmp.Split('|'); result.version = Convert.ToInt32(tmp_list[0]); bd_length = Convert.ToInt32(tmp_list[1]); info = Convert.ToInt32(tmp_list[2]); temp = ByteArrayCut(temp.part2, bd_length); //transaction signature = temp.part2; temp = ByteArrayCut(temp.part1, temp.part1.Length - Transactions.size_info_in_transaction); operations = Encoding.UTF8.GetString(temp.part1); //Debug.WriteLine("operations[1]: " + cryptography.GetHashString(operations)); //Debug.WriteLine("info[1]: " + cryptography.HashToString(cryptography.GetSHA256Hash(temp.part2))); tmp_list = operations.Split('|'); result.input.put = tmp_list[0]; result.input.value = Convert.ToInt32(tmp_list[1]); result.output.put = tmp_list[2]; result.output.value = Convert.ToInt32(tmp_list[3]); result.date = Convert.ToInt32(tmp_list[4]); result.public_key = tmp_list[5]; operations = string.Empty; operations = result.input.put + "|" + result.input.value + "|" + result.output.put + "|" + result.output.value + "|" + result.date + "|" + result.public_key; result.information = ByteArrayGet(temp.part2, info); temp.part1 = Encoding.UTF8.GetBytes(operations); temp.part2 = ByteArrayFill(result.information, Transactions.size_info_in_transaction); body_data = ByteArrayJoin(temp); //Debug.WriteLine("operations[2]: " + cryptography.GetHashString(operations)); //Debug.WriteLine("info[2]: " + cryptography.HashToString(cryptography.GetSHA256Hash(temp.part2))); //window.WriteLine("Body hash: " + cryptography.HashToString(cryptography.GetSHA256Hash(body_data))); //window.WriteLine("Signature hash: " + cryptography.HashToString(cryptography.GetSHA256Hash(signature))); if (cryptography.VerifySign(body_data, signature, result.public_key)) { result.signature = signature; result.name = cryptography.HashToString(cryptography.GetSHA256Hash(data)); } else { window.WriteLine("Transaction checking error"); } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } return(result); }