Kotlin SHA-1
To calculate the SHA-1 hash in Kotlin, you can follow these steps:
- Import the necessary classes:
import java.security.MessageDigest
import java.nio.charset.StandardCharsets
Define a function to calculate the SHA-1 hash:
kotlin fun sha1(input: String): String { val digest = MessageDigest.getInstance("SHA-1") val bytes = digest.digest(input.toByteArray(StandardCharsets.UTF_8)) return bytes.joinToString("") { "%02x".format(it) } }
Call the
sha1
function with your desired input:kotlin val input = "Your input string" val sha1Hash = sha1(input)
Let me know if you have any further questions.