BitSharper.Utils.DoubleDigest C# (CSharp) Method

DoubleDigest() public static method

Calculates the SHA-256 hash of the given byte range, and then hashes the resulting hash again. This is standard procedure in BitCoin. The resulting hash is in big endian form.
public static DoubleDigest ( byte input, int offset, int length ) : byte[]
input byte
offset int
length int
return byte[]
        public static byte[] DoubleDigest(byte[] input, int offset, int length)
        {
            var algorithm = new SHA256Managed();
            var first = algorithm.ComputeHash(input, offset, length);
            return algorithm.ComputeHash(first);
        }

Same methods

Utils::DoubleDigest ( byte input ) : byte[]

Usage Example

Example #1
0
        /// <exception cref="ProtocolException"/>
        protected override void Parse()
        {
            _version          = ReadUint32();
            _prevBlockHash    = ReadHash();
            _merkleRoot       = ReadHash();
            _time             = ReadUint32();
            _difficultyTarget = ReadUint32();
            _nonce            = ReadUint32();

            _hash = new Sha256Hash(Utils.ReverseBytes(Utils.DoubleDigest(Bytes, 0, Cursor)));

            if (Cursor == Bytes.Length)
            {
                // This message is just a header, it has no transactions.
                return;
            }

            var numTransactions = (int)ReadVarInt();

            Transactions = new List <Transaction>(numTransactions);
            for (var i = 0; i < numTransactions; i++)
            {
                var tx = new Transaction(Params, Bytes, Cursor);
                Transactions.Add(tx);
                Cursor += tx.MessageSize;
            }
        }
All Usage Examples Of BitSharper.Utils::DoubleDigest