API Authentication Parameters

All endpoints require the following shared authentication parameters. Use the examples below as a reference.

  • Name
    AccessKeyId
    Type
    string
    Description

    Your access key ID

  • Name
    SignatureNonce
    Type
    string
    Description

    Request nonce

  • Name
    Timestamp
    Type
    string
    Description

    Request timestamp in seconds, valid for 30 seconds

  • Name
    Signature
    Type
    string
    Description

    Signature generated with HmacSHA1 + Base64


Reference Examples

package main

import (
  "crypto/hmac"
  "crypto/sha1"
  "encoding/base64"
  "encoding/hex"
  "fmt"
  "math/rand"
  "strconv"
  "time"
)

// GenerateSignature creates the API signature.
func GenerateSignature(accessKeyId, accessSecret string, signatureNonce *string, timestamp *int64) string {
  nonce := ""
  if signatureNonce == nil {
    b := make([]byte, 4)
    rand.Read(b)
    nonce = hex.EncodeToString(b)
  } else {
    nonce = *signatureNonce
  }

  ts := ""
  if timestamp == nil {
    ts = strconv.FormatInt(time.Now().Unix(), 10)
  } else {
    ts = strconv.FormatInt(*timestamp, 10)
  }

  str := fmt.Sprintf("AccessKeyId=%s&SignatureNonce=%s&Timestamp=%s",
    accessKeyId, nonce, ts)

  h := hmac.New(sha1.New, []byte(accessSecret))
  h.Write([]byte(str))
  hexSignature := hex.EncodeToString(h.Sum(nil))

  return base64.StdEncoding.EncodeToString([]byte(hexSignature))
}

func main() {
  accessKeyId := "975988f45090561684b7d8f4e45b85c2"
  accessSecret := "957f23f2d6435e37d4ac21f3e9a67d45"
  signatureNonce := "2"
  timestamp := int64(1612149637)

  newSignature := GenerateSignature(
    accessKeyId,
    accessSecret,
    &signatureNonce,
    &timestamp,
  )

  oldSignature := "M2Y0ODNlYTUwNDFiMTg5MjRmMGQxNmY1YTMyMzc1NTc5NTUzNDAzYw=="

  if newSignature == oldSignature {
    fmt.Println("Signature verified")
  } else {
    fmt.Println("Signature verification failed")
  }

  fmt.Println("New signature:", newSignature)
}

Was this page helpful?