it there any library have hash 160 for kotlin?
# getting-started
c
it there any library have hash 160 for kotlin?
a
Sorry, I don't understand the question. What do you mean?
h
I believe they're looking for a library implementing https://en.wikipedia.org/wiki/HAS-160 On second thought, they're more likely to look for an implementation of Bitcoin's HASH160 (which actually is RIPEMD160(SHA256(input)))
💡 2
And in that case, https://github.com/komputing/KHash should do it 🙂
a
https://github.com/jonelo/jacksum offers support for HAS-160 (if that is meant). It is a Java-library, but you can use it directly from Kotlin. Here is a sample from someone's cryptography-playground using it: https://github.com/norkator/cryptography/blob/master/src/cryptography/hashes/has/HAS.java
c
how to include them? I included Bouncy Castle but got the
Copy code
java.security.NoSuchAlgorithmException: RIPEMD1600 MessageDigest not available
Copy code
private const val CRYPTO_ALGORITHM_SHA256 = "SHA-256"
private const val CRYPTO_ALGORITHM_RIPEMD160 = "RIPEMD-160"
Copy code
Security.addProvider(BouncyCastleProvider())
            val sha256 = MessageDigest
                .getInstance(CRYPTO_ALGORITHM_SHA256)
                .digest(publicKey.encoded)

            var hash160 = MessageDigest
                .getInstance(CRYPTO_ALGORITHM_RIPEMD160)
                .digest(sha256)
            val str = hash160.toHexString()
finally made it.
Copy code
val d = RIPEMD160Digest()
            d.update(sha256, 0, sha256.size)
            var o = ByteArray(d.digestSize)
            d.doFinal(o, 0)
            return o.toHexString()
seems not integrated into MessageDigest.