title: How does one generate an HMAC string in Elixir?
body: <p>I'm attempting to write an Amazon Product Advertising API client in Elixir. The developer guide describes <a href="http://docs.aws.amazon.com/AWSECommerceService/latest/DG/rest-signature.html">the process for signing an API request</a> in which the an HMAC-SHA26 hash must be created using the request and the "Secret Access Key." This is the function I wrote to handle signing the request:</p>
  
  <pre><code>defp sign_request(url) do
    url_parts = URI.parse(url)
    request = "GET\n" &lt;&gt; url_parts.host &lt;&gt; "\n" &lt;&gt; url_parts.path &lt;&gt; "\n" &lt;&gt; url_parts.query
    url &lt;&gt; "&amp;Signature=" &lt;&gt; :crypto.hmac(:sha256, 'ThisIsMySecretAccessKey', request)
  end
  </code></pre>
  
  <p>The url passed into the function looks something like this: <code>http://webservice.amazon.com/onca/xml?AssociateTag=ThisIsMyAssociateTag&amp;AWSAccessKeyId=ThisIsMyAWSAccessKeyId&amp;Keywords=stuff&amp;Operation=ItemSearch&amp;SearchIndex=Apparel&amp;Service=AWSECommerceService&amp;Timestamp=2014-11-22T12%3A00%3A00Z&amp;Validate=True&amp;Version=2013-08-01</code></p>
  
  <p>The issue I'm having is that, while<code>:crypto.hmac/3</code> returns a binary, that binary is not a string; passing the return value to <code>String.valid?/1</code> returns <code>false</code>. So, I am unable to concatenate the return value onto the end of the url string to sign the request.</p>
  
  <p>Am I using <a href="https://github.com/erlang/otp/blob/maint/lib/crypto/src/crypto.erl#L923"><code>:crypto.hmac/3</code></a> incorrectly? Is there something I'm missing? Is there an alternate way I should be going about this?</p>