public string CalculateTransactionHash(IKeyStore KeyStoreFromAddress) { string blockheader = CreatedDate.ToString(); string transactionHash = ""; foreach (var item in Inputs) { transactionHash += item.GetDataForHash(); } foreach (var item in Outputs) { transactionHash += item.GetDataForHash(); } string combined = transactionHash + blockheader; string completeTransactionHash; if (KeyStoreFromAddress == null || true) { completeTransactionHash = Convert.ToBase64String(HashData.ComputeHashSha256(Encoding.UTF8.GetBytes(combined))); } else { //Not sure need this completeTransactionHash = Convert.ToBase64String(Hmac.ComputeHmacSha256(Encoding.UTF8.GetBytes(combined), KeyStoreFromAddress.AuthenticatedHashKey)); } return(completeTransactionHash); }
public string CalculateProofOfWork() { string difficulty = DifficultyString(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); while (true) { string hashedData = Convert.ToBase64String(HashData.ComputeHashSha256(Encoding.UTF8.GetBytes(Nonce + MyData))); if (hashedData.StartsWith(difficulty, StringComparison.Ordinal)) { stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; // Format and display the TimeSpan value. string elapsedTime = $"{ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}.{ts.Milliseconds / 10:00}"; Console.WriteLine($"Difficulty Level {Difficulty} - Nonce = {Nonce} - Elapsed = {elapsedTime} - {hashedData}"); return(hashedData); } Nonce++; } }
public string CalculateProofOfWork(string blockHash) { var targetPrefix = new string('0', Difficulty); var stopWatch = new Stopwatch(); stopWatch.Start(); for (Nonce = 0; Nonce < int.MaxValue; Nonce++) { var hashedData = Convert.ToBase64String(HashData.ComputeHashSha256(Encoding.UTF8.GetBytes(Nonce + blockHash))); if (hashedData.StartsWith(targetPrefix)) { stopWatch.Stop(); ValueType ts = stopWatch.Elapsed; Console.WriteLine("Difficulty Level {0} - Nonce = {1} - Elapsed = {2} - {3}", Difficulty, Nonce, ts, hashedData); return(hashedData); } } throw new Exception("No nonce found!"); }
public string computeProofOfWork(string InputToHash) { string numberOfZeroes = numberOfStartingZeroes(); Stopwatch stopWatchObj = new Stopwatch(); stopWatchObj.Start(); while (true) { string hashedData = Convert.ToBase64String(HashData.ComputeHashSha256(Encoding.UTF8.GetBytes(Nonce + InputToHash))); if (hashedData.StartsWith(numberOfZeroes, StringComparison.Ordinal)) { stopWatchObj.Stop(); TimeSpan timeSpanObj = stopWatchObj.Elapsed; string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", timeSpanObj.Hours, timeSpanObj.Minutes, timeSpanObj.Seconds, timeSpanObj.Milliseconds / 10); Console.WriteLine("Complexity Level : [" + numberOfZeroes.Length + " Zeroes] ~ Nonce : [" + Nonce + "] ~ Elapsed : [" + elapsedTime + "] ~ [" + hashedData + "]"); return(hashedData); } Nonce++; } }
public bool IsValidChain(string prevBlockHash, bool verbose) { bool isValid = true; bool validSignature = false; validSignature = KeyStore.VerifyBlock(BlockHash, BlockSignature); // Is this a valid block and transaction //string newBlockHash = CalculateBlockHash(prevBlockHash); string newBlockHash = Convert.ToBase64String(HashData.ComputeHashSha256(Encoding.UTF8.GetBytes(Nonce + CalculateBlockHash(prevBlockHash)))); validSignature = KeyStore.VerifyBlock(newBlockHash, BlockSignature); if (newBlockHash != BlockHash) { isValid = false; } else { // Does the previous block hash match the latest previous block hash isValid |= PreviousBlockHash == prevBlockHash; } PrintVerificationMessage(verbose, isValid, validSignature); // Check the next block by passing in our newly calculated blockhash. This will be compared to the previous // hash in the next block. They should match for the chain to be valid. if (NextBlock != null) { return(NextBlock.IsValidChain(newBlockHash, verbose)); } return(isValid); }
public string CalculateProofOfWork(string blockHash) { string difficulty = DifficultyString(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); while (true) { string hashedData = Convert.ToBase64String(HashData.ComputeHashSha256(Encoding.UTF8.GetBytes(Nonce + blockHash))); if (hashedData.StartsWith(difficulty, StringComparison.Ordinal)) { stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; // Format and display the TimeSpan value. string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Console.WriteLine("Difficulty Level " + Difficulty + " - Nonce = " + Nonce + " - Elapsed = " + elapsedTime + " - " + hashedData); return(hashedData); } Nonce++; } }
public string calculateBlockHash(string previousBlockHash) { string blockHeaderHash = BlockNumber + BlockCreationDate.ToString() + previousBlockHash; string finalBlockHash = merkleTreeObj.RootNode + blockHeaderHash; return(Convert.ToBase64String(HashData.ComputeHashSha256(Encoding.UTF8.GetBytes(finalBlockHash)))); }
public void CalculateProofOfWork() { var targetPrefix = new string('0', _level); var hash = string.Empty; int nonce; var start = DateTime.UtcNow; for (nonce = 0; nonce < int.MaxValue; nonce++) { var toBeHashed = $"{nonce}{_message}"; hash = Convert.ToBase64String(HashData.ComputeHashSha256(Encoding.UTF8.GetBytes(toBeHashed))); if (hash.StartsWith(targetPrefix)) { break; } } var done = DateTime.UtcNow; var elapsed = done.Subtract(start); Console.WriteLine("Difficulty Level {0} - Nonce = {1} - Elapsed = {2} - {3}", _level, nonce, elapsed, hash); }
public string CalculateBlockHash(string previousBlockHash) { var blockheader = BlockNumber + CreatedDate.ToString() + previousBlockHash; var combined = merkleTree.RootNode + blockheader; return(Convert.ToBase64String(HashData.ComputeHashSha256(Encoding.UTF8.GetBytes(combined)))); }
public string CalculateTransactionHash() { string songDetailString = null; songDetailString = SongNumber + SongName + AlbumName + ArtistOrBand + PublicationLabel + OwnershipPercentagePerBandMember; return(Convert.ToBase64String(HashData.ComputeHashSha256(Encoding.UTF8.GetBytes(songDetailString)))); }
public string CalculateBlockHash(string previousBlockHash) { string txnHash = ClaimNumber + SettlementAmount + SettlementDate + CarRegistration + Mileage + ClaimType; string blockheader = BlockNumber + CreatedDate.ToString() + previousBlockHash; string combined = txnHash + blockheader; return(Convert.ToBase64String(HashData.ComputeHashSha256(Encoding.UTF8.GetBytes(combined)))); }
private void btnHash256_Click(object sender, EventArgs e) { string chuoi1; chuoi1 = this.txtChuoiCanHash.Text.Trim(); var sha256HashedMessage = HashData.ComputeHashSha256(Encoding.UTF8.GetBytes(chuoi1)); this.txtMaBam.Text = Convert.ToBase64String(sha256HashedMessage); }
public string CalculateBlockHash(string previousBlockHash) { string blockheader = BlockNumber + CreatedDate.ToString() + previousBlockHash; string combined = merkleTree.RootNode + blockheader; string completeBlockHash; if (KeyStore == null) { completeBlockHash = Convert.ToBase64String(HashData.ComputeHashSha256(Encoding.UTF8.GetBytes(combined))); } else { completeBlockHash = Convert.ToBase64String(Hmac.ComputeHmacsha256(Encoding.UTF8.GetBytes(combined), KeyStore.AuthenticatedHashKey)); } return(completeBlockHash); }
private static void TestHashingAPI() { const string originalMessage = "Original message to hash"; const string originalMessage2 = "Or1ginal message to hash"; Console.WriteLine($"Original Message 1: {originalMessage}"); Console.WriteLine($"Original Message 2: {originalMessage2}"); Console.WriteLine(); var mdHashedMessage = HashData.ComputeHashMd5(Encoding.UTF8.GetBytes(originalMessage)); var mdHashedMessage2 = HashData.ComputeHashMd5(Encoding.UTF8.GetBytes(originalMessage2)); var sha1HashedMessage = HashData.ComputeHashSha1(Encoding.UTF8.GetBytes(originalMessage)); var sha1HashedMessage2 = HashData.ComputeHashSha1(Encoding.UTF8.GetBytes(originalMessage2)); var sha256HashedMessage = HashData.ComputeHashSha256(Encoding.UTF8.GetBytes(originalMessage)); var sha256HashedMessage2 = HashData.ComputeHashSha256(Encoding.UTF8.GetBytes(originalMessage2)); var sha512HashedMessage = HashData.ComputeHashSha512(Encoding.UTF8.GetBytes(originalMessage)); var sha512HashedMessage2 = HashData.ComputeHashSha512(Encoding.UTF8.GetBytes(originalMessage2)); Console.WriteLine(); Console.WriteLine($"MD5 Message 1: {Convert.ToBase64String(mdHashedMessage)}"); Console.WriteLine($"MD5 Message 2: {Convert.ToBase64String(mdHashedMessage2)}"); Console.WriteLine(); Console.WriteLine(); Console.WriteLine($"SHA1 Message 1: {Convert.ToBase64String(sha1HashedMessage)}"); Console.WriteLine($"SHA1 Message 2: {Convert.ToBase64String(sha1HashedMessage2)}"); Console.WriteLine(); Console.WriteLine(); Console.WriteLine($"SHA256 Message 1: {Convert.ToBase64String(sha256HashedMessage)}"); Console.WriteLine($"SHA256 Message 2: {Convert.ToBase64String(sha256HashedMessage2)}"); Console.WriteLine(); Console.WriteLine(); Console.WriteLine($"SHA512 Message 1: {Convert.ToBase64String(sha512HashedMessage)}"); Console.WriteLine($"SHA512 Message 2: {Convert.ToBase64String(sha512HashedMessage2)}"); Console.WriteLine(); }
private void btn_signEncryption_Click(object sender, EventArgs e) { string plainText = tb_plainText.Text.Trim(); if (plainText != "") { writeLog("Converting " + plainText + " to byte..."); byte[] data = Encoding.UTF8.GetBytes(plainText); writeLog("Hashing data with SHA256..."); byte[] sha256Hashed = HashData.ComputeHashSha256(data); tb_hash.Text = Convert.ToBase64String(sha256Hashed); writeLog("Complete hash your text."); writeLog("Using the private key to encrypt your text"); byte[] signData = rsa.SignData(sha256Hashed); tb_signature.Text = Convert.ToBase64String(signData); writeLog("-------------- The signature is created! --------------"); } else { AlertError("Nothing to sign."); } }
public string CalculateTransactionHash() { string txnHash = ClaimNumber + SettlementAmount + SettlementDate + CarRegistration + Mileage + ClaimType; return(Convert.ToBase64String(HashData.ComputeHashSha256(Encoding.UTF8.GetBytes(txnHash)))); }
public byte[] CalculateTransactionHash() { string txnHash = ID + Name + Type + Timestamp; return(HashData.ComputeHashSha256(Encoding.UTF8.GetBytes(txnHash))); }