Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Security.Cryptography;
- namespace Models
- {
- public class Block
- {
- public int Index { get; set; }
- public Int64 TimeStamp { get; set; }
- public byte[] PrevHash { get; set; }
- public byte[] Hash { get; set; }
- public byte[] Transaction { get; set; }
- public Block( byte[] prevHash, byte[] transaction)
- {
- Index = 0;
- PrevHash = prevHash;
- TimeStamp = DateTime.Now.Ticks;
- Transaction = transaction;
- Hash = GenerateHash();
- }
- public byte[] GenerateHash()
- {
- SHA256 sha256 = SHA256.Create();
- byte[] tStamp = BitConverter.GetBytes(TimeStamp);
- byte[] sumBytes = new byte[tStamp.Length + PrevHash.Length + Transaction.Length];
- System.Buffer.BlockCopy(tStamp, 0, sumBytes, 0, tStamp.Length);
- System.Buffer.BlockCopy(PrevHash, 0, sumBytes, tStamp.Length, PrevHash.Length);
- System.Buffer.BlockCopy(Transaction, 0, sumBytes, tStamp.Length + PrevHash.Length, Transaction.Length);
- byte[] hashBytes = sha256.ComputeHash(sumBytes);
- return hashBytes;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement