title: Node JS crypto, cannot create hmac on chars with accents
body: <p>I am having an issue generating the correct signature in NodeJS (using crypto.js) when the text I am trying to encrypt has accented characters (such as ä,ï,ë)</p>
  
  <pre><code>generateSignature = function (str, secKey) { 
   var hmac = crypto.createHmac('sha1', secKey);
   var sig = hmac.update(str).digest('hex');
   return sig;
  };
  </code></pre>
  
  <p>This function will return the correct HMAC signature if 'str' contains no accented characters  (chars such as ä,ï,ë). If there are accented chars present in the text, it will not return the correct HMAC. The accented characters are valid in UTF8 encoding so I dont know why crypto has a problem with them. It may be the case that I need to somehow tell crypto that I am signing utf8 encoded text, but I don't know how to do this.</p>
  
  <p>The exact same problem is described in this post: <a href="https://stackoverflow.com/questions/9463157/nodejs-hmac-digest-issue-with-accents">NodeJS hmac digest issue with accents</a>
  However, the post itself, as well as the answer, do not make sense to me (as they are passing the data they want to encrypt where the secret key should go). </p>
  
  <p>Here is a version of the code with hard coded values for str and secKey:</p>
  
  <pre><code>  var crypto = require('crypto');
  
    str="äïë";  
    secKey="secret"; 
    var hmac = crypto.createHmac('sha1', secKey);
    var sig = hmac.update(new Buffer(str, 'utf8')).digest('hex');
    console.log("Sig:      " + sig);
    console.log("Expected: 094b2ba039775bbf970a58e4a0a61b248953d30b"); 
    // "Expected" was generated using http://hash.online-convert.com/sha1-generator
  </code></pre>
  
  <p>Output::</p>
  
  <p>Sig:      39c9f1a6094c76534157739681456e7878557f58</p>
  
  <p>Expected: 094b2ba039775bbf970a58e4a0a61b248953d30b</p>
  
  <p>Thanks </p>