signature.go 454 B

1234567891011121314151617181920
  1. package encryptor
  2. import (
  3. "crypto/md5"
  4. "encoding/hex"
  5. "strconv"
  6. )
  7. // Sign calculates the aispeech request signature.
  8. func Sign(token string, timestamp int64, nonce string, body []byte) string {
  9. bodyMD5 := md5.Sum(body)
  10. bodySign := hex.EncodeToString(bodyMD5[:])
  11. h := md5.New()
  12. h.Write([]byte(token))
  13. h.Write([]byte(strconv.FormatInt(timestamp, 10)))
  14. h.Write([]byte(nonce))
  15. h.Write([]byte(bodySign))
  16. return hex.EncodeToString(h.Sum(nil))
  17. }