Message Authentication Code

Example message authentication: Note, will use byteutils

 import tsec.common._
 import tsec.mac.jca._

Default Pure version with usage of cats effect Sync[F]

  val toMac: Array[Byte] = "hi!".utf8Bytes

  import cats.syntax.all._
  import cats.effect.Sync

  /** For Interpetation into any F */
  def `mac'd-pure`[F[_]: Sync]: F[Boolean] =
    for {
      key       <- HMACSHA256.generateKey[F]                //Generate our key.
      macValue  <- HMACSHA256.sign[F](toMac, key)                   //Generate our MAC bytes
      verified  <- HMACSHA256.verifyBool[F](toMac, macValue, key)       //Verify a byte array with a signed, typed instance
    } yield verified

To use the impure version:

  val `mac'd`: Either[Throwable, Boolean] = for {
    key       <- HMACSHA256.generateKey[MacErrorM]                        //Generate our key.
    macValue  <- HMACSHA256.sign[MacErrorM](toMac, key)                   //Generate our MAC bytes
    verified  <- HMACSHA256.verifyBool[MacErrorM](toMac, macValue, key)   //Verify a byte array with a signed, typed instance
  } yield verified