RIPEMD-160 is a cryptographic hash function that produces a 160-bit hash value. It was developed as an alternative to SHA-1 and is commonly used in cryptocurrency applications and other security contexts.
Creates RIPEMD-160 hash instances for generating 160-bit cryptographic hash values.
/**
* Creates a new RIPEMD-160 hash instance
* @returns RIPEMD-160 hash instance
*/
function ripemd160(): RIPEMD160Instance;
interface RIPEMD160Instance extends BlockHash {
blockSize: 512;
outSize: 160;
hmacStrength: 192;
padLength: 64;
endian: 'little';
}Usage Examples:
const hash = require('hash.js');
// Basic RIPEMD-160 hashing
const digest = hash.ripemd160().update('hello world').digest('hex');
console.log(digest); // "98c615784ccb5fe5936fbc0cbe9dfdb408d92f0f"
// Empty string hash
const emptyDigest = hash.ripemd160().update('').digest('hex');
console.log(emptyDigest); // "9c1185a5c5e9fc54612808977ee8f548b2258d31"
// Message digest
const messageDigest = hash.ripemd160().update('message digest').digest('hex');
console.log(messageDigest); // "5d0689ef49d2fae572b881b123a85ffa21595f36"
// Incremental hashing
const hasher = hash.ripemd160();
hasher.update('abc');
hasher.update('dbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq');
const result = hasher.digest('hex');
console.log(result); // "12a053384a9c0c88e405a06c27dcf49ada62eb2b"RIPEMD-160 can output hash values as byte arrays for binary processing:
const hash = require('hash.js');
// Get hash as byte array
const binaryHash = hash.ripemd160().update('test data').digest();
console.log(binaryHash); // Array of 20 bytes (160 bits / 8)
// Convert byte array to hex manually
const hexString = binaryHash.map(b => b.toString(16).padStart(2, '0')).join('');RIPEMD-160 can process hexadecimal-encoded input data:
const hash = require('hash.js');
// Process hex-encoded data
const hexDigest = hash.ripemd160().update('deadbeef', 'hex').digest('hex');
// Mixed text and hex processing
const hasher = hash.ripemd160();
hasher.update('prefix-');
hasher.update('cafe', 'hex'); // Hex bytes
hasher.update('-suffix');
const result = hasher.digest('hex');RIPEMD-160 efficiently handles large amounts of data through incremental updates:
const hash = require('hash.js');
// Process large data incrementally
const hasher = hash.ripemd160();
// Simulate processing chunks of data
const largeData = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
hasher.update(largeData);
const finalDigest = hasher.digest('hex');
console.log(finalDigest); // "b0e20b6e3116640286ed3a87a5713079b21f5189"RIPEMD-160 has specific characteristics that differentiate it from SHA functions:
// Static properties available on the constructor
interface RIPEMD160Constructor {
blockSize: 512; // Block size in bits
outSize: 160; // Output size in bits
hmacStrength: 192; // HMAC security strength
padLength: 64; // Padding length in bytes
}
// Instance properties
interface RIPEMD160Instance {
endian: 'little'; // Uses little-endian byte order (unlike SHA functions)
}Property Access:
const hash = require('hash.js');
// Access static properties
console.log(hash.ripemd160.blockSize); // 512
console.log(hash.ripemd160.outSize); // 160
console.log(hash.ripemd160.hmacStrength); // 192
console.log(hash.ripemd160.padLength); // 64
// Instance shows endianness
const hasher = hash.ripemd160();
console.log(hasher.endian); // 'little'RIPEMD-160 can be used with HMAC for message authentication:
const hash = require('hash.js');
// RIPEMD-160 based HMAC
const hmacDigest = hash.hmac(hash.ripemd160, 'secret-key')
.update('message to authenticate')
.digest('hex');
console.log(hmacDigest); // HMAC-RIPEMD160 digestRIPEMD-160 is also available through the ripemd namespace:
interface RipemdNamespace {
ripemd160: typeof ripemd160;
}
const ripemd: RipemdNamespace;Usage:
const hash = require('hash.js');
// Access via namespace
const digest1 = hash.ripemd.ripemd160().update('test').digest('hex');
// Direct access (equivalent)
const digest2 = hash.ripemd160().update('test').digest('hex');
console.log(digest1 === digest2); // true