Skip to content

Commit

Permalink
Add Android implementation of crypto shim
Browse files Browse the repository at this point in the history
  • Loading branch information
nodh committed Sep 27, 2024
1 parent 5571496 commit 9bccbbf
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import at.asitplus.KmmResult
import at.asitplus.KmmResult.Companion.wrap
import at.asitplus.signum.indispensable.josef.*
import javax.crypto.Cipher
import javax.crypto.Mac
import javax.crypto.spec.GCMParameterSpec
import javax.crypto.spec.SecretKeySpec

Expand Down Expand Up @@ -78,5 +79,15 @@ actual open class PlatformCryptoShim actual constructor(actual val keyMaterial:
return KmmResult.success("sharedSecret-${algorithm.identifier}".encodeToByteArray())
}

actual fun hmac(
key: ByteArray,
algorithm: JweEncryption,
input: ByteArray,
): KmmResult<ByteArray> = runCatching {
Mac.getInstance(algorithm.jcaHmacName).also {
it.init(SecretKeySpec(key, algorithm.jcaKeySpecName))
}.doFinal(input)
}.wrap()

}

0 comments on commit 9bccbbf

Please sign in to comment.