ripemd160
Calculates the RIPEMD-160 hash of a byte array or hex value
ripemd160
Calculates the RIPEMD-160 hash of a byte array or hex value. This hash function is used in Bitcoin address generation.
Import
import "github.com/ChefBingbong/viem-go/utils/hash"Usage
import "github.com/ChefBingbong/viem-go/utils/hash"
// Hash bytesh := hash.Ripemd160([]byte("hello world"))// "0x98c615784ccb5fe5936fbc0cbe9dfdb408d92f0f"
// Hash hex stringh = hash.Ripemd160("0x68656c6c6f20776f726c64")// "0x98c615784ccb5fe5936fbc0cbe9dfdb408d92f0f"
// Hash string (UTF-8)h = hash.Ripemd160("hello world")// "0x98c615784ccb5fe5936fbc0cbe9dfdb408d92f0f"
// Get raw bytesbytes := hash.Ripemd160Bytes([]byte("hello world"))// []byte{...}Returns
- Type:
stringforRipemd160,[]byteforRipemd160Bytes
The hashed value. Ripemd160 returns a hex string with 0x prefix, Ripemd160Bytes returns raw bytes.
Parameters
value (required)
- Type:
any(supports[]byteorstring)
The hex value or byte array to hash. If a string is provided without 0x prefix, it's treated as UTF-8.
// Hash byteshash := hash.Ripemd160([]byte("hello"))
// Hash hex stringhash = hash.Ripemd160("0x68656c6c6f")
// Hash UTF-8 stringhash = hash.Ripemd160("hello")Functions
Ripemd160
Computes RIPEMD-160 hash and returns a hex string:
hash := hash.Ripemd160([]byte("hello"))
// "0x108f07b8382412612c048d07d13f814118445acd"
Ripemd160Bytes
Computes RIPEMD-160 hash and returns raw bytes:
bytes := hash.Ripemd160Bytes([]byte("hello"))
// []byte{0x10, 0x8f, 0x07, ...}