title: Coldfusion HMAC-SHA1 encryption
body: <p>There is an example HMAC-SHA1 here that works in javascript</p>
  
  <p><a href="http://jssha.sourceforge.net/" rel="nofollow">http://jssha.sourceforge.net/</a></p>
  
  <h2>Text to encrypt</h2>
  
  <p>vibaHBXwUXFqVSg-+kTrqYJZEJkbVeqLc=bo.LlXGET12505351831husu9039http://api.tineye.com/rest/search/image_url=http%3a%2f%2ftineye.com%2fimages%2ftineye_logo_big.png&amp;limit=30&amp;offset=10</p>
  
  <h2>Key</h2>
  
  <p>vibaHBXwUXFqVSg-+kTrqYJZEJkbVeqLc=bo.LlX</p>
  
  <h2>Output</h2>
  
  <p>9e734661c9e8b6dc9b6b4b3def9769c00e8843b8</p>
  
  <h2>Issue</h2>
  
  <p>I can't however duplicate the output in Coldfusion. I'm using a function from a previous Stackoverflow.com question</p>
  
  <pre><code>&lt;cffunction name="hmacEncrypt" returntype="binary" access="public" output="false"&gt;
     &lt;cfargument name="signKey" type="string" required="true" /&gt;
     &lt;cfargument name="signMessage" type="string" required="true" /&gt;
  
  
     &lt;cfset var jMsg = JavaCast("string",arguments.signMessage).getBytes("iso-8859-1") /&gt;
     &lt;cfset var jKey = JavaCast("string",arguments.signKey).getBytes("iso-8859-1") /&gt;
  
     &lt;cfset var key = createObject("java","javax.crypto.spec.SecretKeySpec") /&gt;
     &lt;cfset var mac = createObject("java","javax.crypto.Mac") /&gt;
  
     &lt;cfset key = key.init(jKey,"HmacSHA1") /&gt;
  
     &lt;cfset mac = mac.getInstance(key.getAlgorithm()) /&gt;
     &lt;cfset mac.init(key) /&gt;
     &lt;cfset mac.update(jMsg) /&gt;
  
     &lt;cfreturn mac.doFinal() /&gt;
  &lt;/cffunction&gt;
  
  &lt;cfset result = hmacEncrypt("vibaHBXwUXFqVSg-+kTrqYJZEJkbVeqLc=bo.LlX", "vibaHBXwUXFqVSg-+kTrqYJZEJkbVeqLc=bo.LlXGET12505351831husu9039http://api.tineye.com/rest/search/image_url=http%3a%2f%2ftineye.com%2fimages%2ftineye_logo_big.png&amp;limit=30&amp;offset=10")&gt;
  
  &lt;cfset x1 = toString(tobase64(result))&gt;
  </code></pre>
  
  <h2>This returns</h2>
  
  <p>nnNGYcnottyba0s975dpwA6IQ7g=</p>
  
  <p>Any help appreciated.</p>
  
  <p></p>