Skip to content

Instantly share code, notes, and snippets.

@holys
Last active August 29, 2015 14:07
Show Gist options
  • Save holys/20f7efa17b5cb3f83756 to your computer and use it in GitHub Desktop.
Save holys/20f7efa17b5cb3f83756 to your computer and use it in GitHub Desktop.
xiaomi oauth signature
package main
import (
"crypto/hmac"
"crypto/sha1"
"encoding/base64"
"fmt"
"io"
"net/url"
)
func main() {
sign_string := "this is sign string"
mac_key := "this is mac key"
m := hmac.New(sha1.New, []byte(mac_key))
io.WriteString(m, sign_string)
// sign := fmt.Sprintf("%x", m.Sum(nil))
// fmt.Println(sign)
h := base64.StdEncoding.EncodeToString(m.Sum(nil))
fmt.Println(url.QueryEscape(h))
}
package main
import (
"crypto/hmac"
"crypto/sha1"
"encoding/base64"
"fmt"
"io"
"net/url"
)
func main() {
sign_string := "this is sign string"
mac_key := "this is mac key"
m := hmac.New(sha1.New, []byte(mac_key))
io.WriteString(m, sign_string)
// sign := fmt.Sprintf("%x", m.Sum(nil))
// fmt.Println(sign)
h := base64.StdEncoding.EncodeToString(m.Sum(nil))
fmt.Println(url.QueryEscape(h))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment