Creating and validating signature is commonly use to verify the authenticity of a request. Heres a tiny kotlin function to generate HMAC signature from string data.

Using the signature generator

val signature = createSignature("myStringData", "mySecretKey")

println(signature)

Base64 Encoding

If you want the signature in base64 format please use this

return Base64
  .getEncoder()
  .encodeToString(sha256Hmac.doFinal(data.toByteArray()))