/// <summary> /// Calculate the SHA256-Hash of the share /// </summary> public byte[] GetHash() { Sha256Digest sha256 = new Sha256Digest(); byte[] hash = new byte[sha256.GetByteLength()]; sha256.BlockUpdate(X, 0, X.Length); sha256.BlockUpdate(Y, 0, Y.Length); sha256.GetByteLength(); sha256.DoFinal(hash, 0); return(hash); }
public static string GetAddressForContract(Transaction.Transaction tx) { string senderAddress = KeyTools.GetAddressFromPublicKey(tx.SenderPubKey); SHA256Managed.Create().ComputeHash(ByteUtil.HexStringToByteArray(senderAddress)); Sha256Digest sha = new Sha256Digest(); byte[] senderAddressBytes = ByteUtil.HexStringToByteArray(senderAddress); sha.BlockUpdate(senderAddressBytes, 0, senderAddressBytes.Count()); int nonce = 0; if (!string.IsNullOrEmpty(tx.Nonce)) { nonce = int.Parse(tx.Nonce); nonce--; } string hexNonce = Validation.IntToHex(nonce, 16); byte[] hexNonceBytes = ByteUtil.HexStringToByteArray(hexNonce); sha.BlockUpdate(hexNonceBytes, 0, hexNonceBytes.Count()); byte[] bytes = new byte[sha.GetByteLength()]; sha.DoFinal(bytes, 0); return(ByteUtil.ByteArrayToHexString(bytes).Substring(24, 40)); }