Generate MD4 Hash using Kotlin

Bouncy Castle library

  1. Add bcprov-jdk15on dependency in the build.gradle file:

build.gradle

dependencies {
    implementation 'org.bouncycastle:bcprov-jdk15on:1.68'
}
  1. Generate MD4 hash:

src/main/kotlin/app/main.kt

package app

import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.bouncycastle.util.encoders.Hex
import java.security.MessageDigest
import java.security.Security

fun main()
{
    Security.addProvider(BouncyCastleProvider())

    val text = "Hello"
    val crypt = MessageDigest.getInstance("MD4")
    crypt.update(text.toByteArray())
    val digest = Hex.toHexString(crypt.digest())

    println(digest)
}

Leave a Comment

Cancel reply

Your email address will not be published.