title: How to convert request.body to a byte array in order to calculate MD5?
body: <p>I'm creating a scala function in a Play! application that authenticates requests to my web-service. The authentication is basically an HMAC authentication. The method receives the type of bodyParser to be used. Since I don't know the type of the -bodyParser, how can I convert request.body to a generic Array[Byte] on which I can run my MD5 processing?</p>
  
  <pre><code>def Authenticated[T](authType : AuthenticationType, bodyParser : BodyParser[T])(f : (Request[T]) =&gt; Result) = {
  
      Action(bodyParser) { request =&gt; 
  
        // Authentication logic starts here
  
        // TODO: Something like: var bodyData : Array[Byte] = request.body.toByteArray()
  
        // The rest is easy...
        var contentMD5 = calculateMD5(bodyDat)
        f(request)
      }
  }
  </code></pre>