title: Incorrect Hmac SHA256 Base64 encoded result in Rust compared to JS approach
body: <p>I'm trying to port a crypto exchange API from JavaScript to Rust. The JavaScript version authenticates and connects. The payload and secret key are signed using Hmac Sha256 and encoded to Base64. Below is the working implementation in JavaScript.</p>
  
  <pre><code>var param = "test";
  var privateKey = "secret";
  var signature = crypto.createHmac('sha256', new Buffer(privateKey, 'utf8'))
      .update(param)
      .digest('base64');
  </code></pre>
  
  <p>It returns the following signature: <code>Aymga2LNFrM+tnkr6MYLFY2Jou46h2/Omogeu0iMCRQ=</code></p>
  
  <p>In Rust i'm using Hmac SHA256 and encoding the result back to Base64 yet i'm unable to get close to the expected signature. Here is my best 2 day attempt at this: </p>
  
  <pre><code>extern crate ring;
  extern crate data_encoding;
  extern crate hex;
  
  use ring::{digest, hmac};
  use data_encoding::BASE64;
  use hex::encode as hex_encode;
  
  fn main() {
      let secret_key = "secret";
      let payload = "test";
      let signed_key = hmac::SigningKey::new(&amp;digest::SHA256, secret_key.as_bytes());
      let signature = hex_encode(hmac::sign(&amp;signed_key, payload.as_bytes()).as_ref());
      let b64_encoded_sig = BASE64.encode(signature.as_ref());
      assert_eq!(b64_encoded_sig, "Aymga2LNFrM+tnkr6MYLFY2Jou46h2/Omogeu0iMCRQ=");
  }
  </code></pre>
  
  <p>This returns the following signature: <code>MDMyOWEwNmI2MmNkMTZiMzNlYjY3OTJiZThjNjBiMTU4ZDg5YTJlZTNhODc2ZmNlOWE4ODFlYmI0ODhjMDkxNA==</code></p>
  
  <p>Would really appreciate getting a point in the right direction, gone around in circles for days now and not sure where exactly i'm going wrong. Thanks. </p>