Hmac-sha1 signature generation using scala

Hi Team,

Please find the code for generating an Hmac-sha1 signature generation code in scala. With the increasing use of hmac authentication and Gatling tool, I guess this will be needed my many people in future , so felt like sharing this with out Gatling community.

import java.util.Base64
import org.apache.commons

import javax.crypto.Mac
import javax.crypto.spec.SecretKeySpec;

object hmac {

def encryptHMACSHA1(value: String, secretKey: String): String = {
val signingKey = new SecretKeySpec(secretKey.getBytes, “HmacSHA1”)
val mac = Mac.getInstance(“HmacSHA1”)
mac.init(signingKey)
convertBytesToHex(mac.doFinal(value.getBytes))
}

def convertBytesToHex(bytes: Seq[Byte]): String = {
val sb = new StringBuilder
for (b ← bytes) {
sb.append(String.format("%02x", Byte.box(b)))
}
sb.toString
}

}

Regards,
Aravind