public string Hash(string valueToHash, string salt, bool saveSaltInResult, int bitLength) { var fullText = string.Concat(valueToHash, salt); var data = Encoding.UTF8.GetBytes(fullText); var sha3 = new Sha3Digest(bitLength); var hashedBytes = new byte[sha3.GetDigestSize()]; var toHashAsBytes = Encoding.ASCII.GetBytes(valueToHash); sha3.BlockUpdate(toHashAsBytes, 0, toHashAsBytes.Length); sha3.DoFinal(hashedBytes, 0); var asString = ByteArrayToString(hashedBytes); var algorithm = 0; if (bitLength == 512) { algorithm = (int)HashAlgorithm.SHA3_512; } else { throw new NotImplementedException($"Cannot find a HashAlgorithm for bit length: {bitLength}"); } if (saveSaltInResult) { return(string.Format("[{0}]{1}{2}", algorithm, salt, asString)); } else { return(string.Format("[{0}]{1}", algorithm, asString)); } }
public byte[] CalculateSha3Hash(byte[] value) { var digest = new Sha3Digest(256); var output = new byte[digest.GetDigestSize()]; digest.BlockUpdate(value, 0, value.Length); digest.DoFinal(output, 0); return(output); }
public static byte[] ComputeSha3Digest(byte[] data, int bitLength) { var digest = new Sha3Digest(bitLength); byte[] buffer = new byte[digest.GetDigestSize()]; digest.BlockUpdate(data, 0, data.Length); digest.DoFinal(buffer, 0); return(buffer); }
public static byte[] ComputeSha3Hash(byte[] data) { var shaHash = new Sha3Digest(); shaHash.BlockUpdate(data, 0, data.Length); byte[] hashedValue = new byte[shaHash.GetDigestSize()]; shaHash.DoFinal(hashedValue, 0); return(hashedValue); }
/// <summary> /// Computes the SHA3 hash /// </summary> /// <param name="data"></param> /// <param name="bitLength"></param> /// <returns></returns> private byte[] ComputeSHA3(byte[] data, int bitLength) { var digest = new Sha3Digest(bitLength); digest.BlockUpdate(data, 0, data.Length); var result = new byte[digest.GetDigestSize()]; digest.DoFinal(result, 0); return(result); }
protected static byte[] ComputeHash(byte[] bytes, int bits) { var digest = new Sha3Digest(bits); var output = new byte[digest.GetDigestSize()]; byte[] message = bytes ?? new byte[0]; digest.BlockUpdate(message, 0, message.Length); digest.DoFinal(output, 0); return(output); }
private static byte[] Sha256(string data) { var input = Encoding.UTF8.GetBytes(data); var digest = new Sha3Digest(256); var output = new byte[digest.GetDigestSize()]; digest.BlockUpdate(input, 0, input.Length); digest.DoFinal(output, 0); return(output); }
public static byte[] GetAddressHash(byte[] publicKey) { var digest = new Sha3Digest(256); var output = new byte[digest.GetDigestSize()]; digest.BlockUpdate(publicKey, 0, publicKey.Length); digest.DoFinal(output, 0); var result = new byte[20]; Array.Copy(output, output.Length - 20, result, 0, 20); return(result); }
public override void Initialize() { HashValue = new byte[_digest.GetDigestSize()]; }