Yet Another OTP generator
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Utils.kt 439B

123456789101112131415
  1. package com.chameth.yaotp.algos
  2. import javax.crypto.Mac
  3. import javax.crypto.spec.SecretKeySpec
  4. private const val HMAC_SHA1_ALGORITHM = "HmacSHA1"
  5. fun hmacSha1(keyMaterial: ByteArray, input: ByteArray): ByteArray {
  6. return with(Mac.getInstance(HMAC_SHA1_ALGORITHM)) {
  7. init(getKey(keyMaterial))
  8. doFinal(input)
  9. }
  10. }
  11. private fun getKey(material: ByteArray) = SecretKeySpec(material, HMAC_SHA1_ALGORITHM)