2.4.1.6. Kotlin

 
import java.security.InvalidKeyException
import java.security.NoSuchAlgorithmException
import javax.crypto.Mac
import javax.crypto.spec.SecretKeySpec
import java.util.Base64
 
fun computeHmacsha512(plainText: String, secretKey: String): String {
    val hmacSha512 = Mac.getInstance("HmacSHA512")
    val secretKeySpec = SecretKeySpec(secretKey.toByteArray(), "HmacSHA512")
    hmacSha512.init(secretKeySpec)
    val hash = hmacSha512.doFinal(plainText.toByteArray())
    return Base64.getEncoder().encodeToString(hash)
}