title: Trouble getting HMACsha256 to produce expected results
body: <p>I'm trying to hook into the Binance API and have discovered that my implementation of HMACsha256 isn't producing the results that the sample documentation (and doing it in the command line) can. I'm trying to improve my knowledge of Go, but can't seem to crack this one.</p>
  
  <p>Here's the documentation (Relevant Sample at "SIGNED Endpoint Examples for POST /api/v1/order"): <a href="https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md" rel="nofollow noreferrer">https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md</a></p>
  
  <p>Without looking at the doc, here is the gist, my key is the following:</p>
  
  <pre><code>NhqPtmdSJYdKjVHjA7PZj4Mge3R5YNiP1e3UZjInClVN65XAbvqqM6A7H5fATj0j
  </code></pre>
  
  <p>my value is the following:</p>
  
  <pre><code>symbol=LTCBTC&amp;side=BUY&amp;type=LIMIT&amp;timeInForce=GTC&amp;quantity=1&amp;price=0.1&amp;recvWindow=5000&amp;timestamp=1499827319559
  </code></pre>
  
  <p>When I use the terminal with the following command:</p>
  
  <pre><code>echo -n "symbol=LTCBTC&amp;side=BUY&amp;type=LIMIT&amp;timeInForce=GTC&amp;quantity=1&amp;price=0.1&amp;recvWindow=5000&amp;timestamp=1499827319559" | openssl dgst -sha256 -hmac "NhqPtmdSJYdKjVHjA7PZj4Mge3R5YNiP1e3UZjInClVN65XAbvqqM6A7H5fATj0j"
  </code></pre>
  
  <p>I receive the result</p>
  
  <pre><code>c8db56825ae71d6d79447849e617115f4a920fa2acdcab2b053c4b2838bd6b71
  </code></pre>
  
  <p>Which is what the documentation suggests. But when I use the following go program: </p>
  
  <pre><code>package main
  
  import (
      "crypto/hmac"
      "crypto/sha256"
      "encoding/base64"
      "fmt"
  )
  
  func main() {
      docSecret := "NhqPtmdSJYdKjVHjA7PZj4Mge3R5YNiP1e3UZjInClVN65XAbvqqM6A7H5fATj0j"
      docQuery := "symbol=LTCBTC&amp;side=BUY&amp;type=LIMIT&amp;timeInForce=GTC&amp;quantity=1&amp;price=0.1&amp;recvWindow=5000&amp;timestamp=1499827319559"
      result := hmacify(docQuery, docSecret)
      fmt.Println(result)
  }
  
  func hmacify(message string, secret string) string {
      key := []byte(secret)
      h := hmac.New(sha256.New, key)
      h.Write([]byte(message))
      return base64.StdEncoding.EncodeToString(h.Sum(nil))
  }
  </code></pre>
  
  <p>produces the result:</p>
  
  <pre><code>yNtWglrnHW15RHhJ5hcRX0qSD6Ks3KsrBTxLKDi9a3E=
  </code></pre>
  
  <p>What am I misunderstanding that's causing such a massive difference from the sample and command line?</p>