public Address(Byte[] data, Byte version = PUBKEY) { SHA256 sha256 = SHA256.Create(); IDigest ripemd160 = new RipeMD160Digest(); switch (version) { case PUBKEY: byte[] pubKeySHA256Res = sha256.ComputeHash(data); ripemd160.BlockUpdate(pubKeySHA256Res, 0, pubKeySHA256Res.Length); byte[] pubKeyResult = new byte[ripemd160.GetDigestSize()]; ripemd160.DoFinal(pubKeyResult, 0); pubKeyHash = pubKeyResult; version = PUBKEYHASH; break; case SCRIPT: byte[] scriptSHA256Res = sha256.ComputeHash(data); ripemd160.BlockUpdate(scriptSHA256Res, 0, scriptSHA256Res.Length); byte[] scriptResult = new byte[ripemd160.GetDigestSize()]; ripemd160.DoFinal(scriptResult, 0); scriptHash = scriptResult; version = SCRIPTHASH; break; case PUBKEYHASH: pubKeyHash = data; break; case SCRIPTHASH: scriptHash = data; break; } this.type = version; }
public static byte[] Hash160(byte[] bytes) { var digest = new RipeMD160Digest(); var output = new byte[digest.GetDigestSize()]; digest.BlockUpdate(bytes, 0, bytes.Length); digest.DoFinal(output, 0); return(output); }
/// <summary> /// Ripemd160 hash /// </summary> static public byte[] RipeMD160Hash(byte[] data) { RipeMD160Digest digest = new RipeMD160Digest(); digest.BlockUpdate(data, 0, data.Length); byte[] hash = new byte[digest.GetDigestSize()]; digest.DoFinal(hash, 0); return(hash); }
public static byte[] ComputeRIPEMD160(byte[] data) { IDigest digest = new RipeMD160Digest(); byte[] buffer = new byte[digest.GetDigestSize()]; digest.BlockUpdate(data, 0, data.Length); digest.DoFinal(buffer, 0); return(buffer); }
public static byte[] RIPEMD160(byte[] data) { var digest = new RipeMD160Digest(); var result = new byte[digest.GetDigestSize()]; digest.BlockUpdate(data, 0, data.Length); digest.DoFinal(result, 0); return(result); }
public static byte[] RIPEMD160(byte[] data) { RipeMD160Digest ripemd160 = new RipeMD160Digest(); ripemd160.BlockUpdate(data, 0, data.Length); byte[] buffer = new byte[ripemd160.GetDigestSize()]; ripemd160.DoFinal(buffer, 0); return(buffer); }
public static ExtraHashAlgorithm CreateRipeMD160() { var ha = new RipeMD160Digest(); return(new ExtraHashAlgorithm( ha.AlgorithmName, ha.GetDigestSize(), ha.Reset, ha.BlockUpdate, ha.DoFinal )); }
public static byte[] RipeMD160(this IEnumerable <byte> input) { var block = input.ToArray(); RipeMD160Digest.BlockUpdate(block, 0, block.Length); var output = new byte[RipeMD160Digest.GetDigestSize()]; RipeMD160Digest.DoFinal(output, 0); return(output); }
public static byte[] Hash160(byte[] message) { var digest = new RipeMD160Digest(); var output = new byte[digest.GetDigestSize()]; byte[] msg = message ?? new byte[0]; digest.BlockUpdate(msg, 0, msg.Length); digest.DoFinal(output, 0); return(output); }
private static string CalcRipeMD160(string text) { byte[] bytes = Encoding.UTF8.GetBytes(text); RipeMD160Digest digest = new RipeMD160Digest(); digest.BlockUpdate(bytes, 0, bytes.Length); byte[] result = new byte[digest.GetDigestSize()]; digest.DoFinal(result, 0); return(BytesToHex(result)); }
public static string CalcRIPEMD160(byte[] keyBytes) { var digest = new RipeMD160Digest(); digest.BlockUpdate(keyBytes, 0, keyBytes.Length); var result = new byte[digest.GetDigestSize()]; digest.DoFinal(result, 0); return(BytesToHex(result)); }
public override byte[] ComputeHash(byte[] input, int offset, int count) { var ripemd160 = new RipeMD160Digest(); var result = new byte[ripemd160.GetDigestSize()]; ripemd160.BlockUpdate(input, offset, count); ripemd160.DoFinal(result, 0); return(result); }
/// <summary> /// Converts a public key to a local address (which is used as unique identifier within a DAppChain). /// </summary> /// <param name="publicKey">32-byte public key</param> /// <returns>Array of bytes representing a local address.</returns> public static byte[] LocalAddressFromPublicKey(byte[] publicKey) { lock (ripeMd160Digest) { ripeMd160Digest.Reset(); ripeMd160Digest.BlockUpdate(publicKey, 0, publicKey.Length); byte[] address = new byte[ripeMd160Digest.GetDigestSize()]; ripeMd160Digest.DoFinal(address, 0); return(address); } }
/// <summary> /// Gets the RIPEMD160 digest for the specified data. /// </summary> /// <param name="data">The data.</param> /// <returns>The digest string.</returns> public static string GetRipemd160(MemoryStream data) { var digest = new RipeMD160Digest(); digest.BlockUpdate(data.ToArray(), 0, (int)data.Length); var result = new byte[digest.GetDigestSize()]; digest.DoFinal(result, 0); return(BitConverter.ToString(result).Replace("-", "")); }
public static string ComputeRipeMd160Hash(this string valueForHash) { var ripeMd160 = new RipeMD160Digest(); var hash = new byte[ripeMd160.GetDigestSize()]; foreach (var @byte in Encoding.UTF8.GetBytes(valueForHash)) { ripeMd160.Update(@byte); } ripeMd160.DoFinal(hash, 0); return(Hex.ToHexString(hash)); }
/// <summary> /// Gets the digest for the specified assembly. /// </summary> /// <param name="assembly">The assembly to calculate the digest from.</param> /// <returns>The digest string.</returns> public static string GetDigestFromAssembly(Assembly assembly) { var digest = new RipeMD160Digest(); var data = File.ReadAllBytes(assembly.Location); digest.BlockUpdate(data, 0, data.Length); var result = new byte[digest.GetDigestSize()]; digest.DoFinal(result, 0); return(BitConverter.ToString(result).Replace("-", "")); }
public string CalcRipeMD160(string text) { byte[] bytes = Encoding.UTF8.GetBytes(text); RipeMD160Digest digest = new RipeMD160Digest(); digest.BlockUpdate(bytes, 0, bytes.Length); byte[] result = new byte[digest.GetDigestSize()]; digest.DoFinal(result, 0); return(this.ConvertByteArrayToHexStringV1(result)); }
private static string CalculateRipeMD160Digest(string text) { byte[] bytes = Encoding.UTF8.GetBytes(text); //RIPEMD160Managed hashstring = new RIPEMD160Managed(); //string tt = hashstring.ComputeHash(bytes) RipeMD160Digest digest = new RipeMD160Digest(); digest.BlockUpdate(bytes, 0, bytes.Length); byte[] result = new byte[digest.GetDigestSize()]; digest.DoFinal(result, 0); return(BytesToHex(result)); }
/// <summary> /// Calculates RIPEMD160(SHA256(input)). This is used in Address calculations. /// </summary> public static byte[] Sha256Hash160(byte[] input) { var sha256 = new Sha256Digest(); var digest = new RipeMD160Digest(); sha256.BlockUpdate(input, 0, input.Length); var @out256 = new byte[sha256.GetDigestSize()]; sha256.DoFinal(@out256, 0); digest.BlockUpdate(@out256, 0, @out256.Length); var @out = new byte[digest.GetDigestSize()]; digest.DoFinal(@out, 0); return(@out); }
/// <summary> /// Gets the RIPEMD160 digest for the specified filename. /// </summary> /// <param name="filename">The filename.</param> /// <returns>The digest string.</returns> public static string GetRipemd160(string filename) { using (var fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Delete | FileShare.ReadWrite)) { byte[] buffer = new byte[4092]; int bytesRead; var digest = new RipeMD160Digest(); while ((bytesRead = fs.Read(buffer, 0, buffer.Length)) > 0) { digest.BlockUpdate(buffer, 0, bytesRead); } var result = new byte[digest.GetDigestSize()]; digest.DoFinal(result, 0); return(BitConverter.ToString(result).Replace("-", "")); } }
public ITestResult Perform() { IDigest digest = new RipeMD160Digest(); byte[] resBuf = new byte[digest.GetDigestSize()]; for (int i = 0; i < messages.Length; i++) { byte[] m = Encoding.ASCII.GetBytes(messages[i]); digest.BlockUpdate(m, 0, m.Length); digest.DoFinal(resBuf, 0); if (!Arrays.AreEqual(resBuf, Hex.Decode(digests[i]))) { return(new SimpleTestResult(false, Name + ": Vector " + i + " failed")); } } // // test 2 // byte[] mm = Encoding.ASCII.GetBytes(messages[messages.Length - 1]); digest.BlockUpdate(mm, 0, mm.Length / 2); // clone the IDigest IDigest d = new RipeMD160Digest((RipeMD160Digest)digest); digest.BlockUpdate(mm, mm.Length / 2, mm.Length - mm.Length / 2); digest.DoFinal(resBuf, 0); if (!Arrays.AreEqual(resBuf, Hex.Decode(digests[digests.Length - 1]))) { return(new SimpleTestResult(false, "RipeMD160 failing clone test" + SimpleTest.NewLine + " expected: " + digests[digests.Length - 1] + SimpleTest.NewLine + " got : " + Hex.ToHexString(resBuf))); } d.BlockUpdate(mm, mm.Length / 2, mm.Length - mm.Length / 2); d.DoFinal(resBuf, 0); if (!Arrays.AreEqual(resBuf, Hex.Decode(digests[digests.Length - 1]))) { return(new SimpleTestResult(false, "RipeMD160 failing clone test - part 2" + SimpleTest.NewLine + " expected: " + digests[digests.Length - 1] + SimpleTest.NewLine + " got : " + Hex.ToHexString(resBuf))); } for (int i = 0; i < 1000000; i++) { digest.Update((byte)'a'); } digest.DoFinal(resBuf, 0); if (!Arrays.AreEqual(resBuf, Hex.Decode(MillionADigest))) { return(new SimpleTestResult(false, Name + ": Million a's failed")); } return(new SimpleTestResult(true, Name + ": Okay")); }
public static byte[] Digest(byte[] data, String algo) { if (algo == null) { throw new ArgumentNullException("El algoritmo de huella digital no puede ser nulo"); } if (data == null) { throw new ArgumentNullException("Los datos no pueden ser nulos"); } switch (algo) { /** * ALGORITMOS DE HASING */ case AOSignConstants.SIGN_ALGORITHM_SHA1: { Sha1Digest dig = new Sha1Digest(); dig.BlockUpdate(data, 0, data.Length); byte[] result = new byte[dig.GetDigestSize()]; dig.DoFinal(result, 0); return(result); } case AOSignConstants.SIGN_ALGORITHM_SHA256: { Sha256Digest dig = new Sha256Digest(); dig.BlockUpdate(data, 0, data.Length); byte[] result = new byte[dig.GetDigestSize()]; dig.DoFinal(result, 0); return(result); } case AOSignConstants.SIGN_ALGORITHM_SHA384: { Sha384Digest dig = new Sha384Digest(); dig.BlockUpdate(data, 0, data.Length); byte[] result = new byte[dig.GetDigestSize()]; dig.DoFinal(result, 0); return(result); } case AOSignConstants.SIGN_ALGORITHM_SHA512: { Sha512Digest dig = new Sha512Digest(); dig.BlockUpdate(data, 0, data.Length); byte[] result = new byte[dig.GetDigestSize()]; dig.DoFinal(result, 0); return(result); } case AOSignConstants.SIGN_ALGORITHM_RIPEMD160: { RipeMD160Digest dig = new RipeMD160Digest(); dig.BlockUpdate(data, 0, data.Length); byte[] result = new byte[dig.GetDigestSize()]; dig.DoFinal(result, 0); return(result); } case AOSignConstants.SIGN_ALGORITHM_MD5: { MD5Digest dig = new MD5Digest(); dig.BlockUpdate(data, 0, data.Length); byte[] result = new byte[dig.GetDigestSize()]; dig.DoFinal(result, 0); return(result); } case AOSignConstants.SIGN_ALGORITHM_MD2: { MD2Digest dig = new MD2Digest(); dig.BlockUpdate(data, 0, data.Length); byte[] result = new byte[dig.GetDigestSize()]; dig.DoFinal(result, 0); return(result); } default: // You can use the default case. throw new ArgumentNullException("El algoritmo no es reconocido"); } throw new ArgumentNullException("Algoritmo de hash no soportado: " + algo); }