Skip to content

Instantly share code, notes, and snippets.

@optman
Created December 8, 2015 03:41
Show Gist options
  • Save optman/7abfb399f3d56134fdef to your computer and use it in GitHub Desktop.
Save optman/7abfb399f3d56134fdef to your computer and use it in GitHub Desktop.
baofeng cloud token
import hmac
import hashlib
import base64
def create_token(msg, accessKey, secretKey):
encodedMsg = base64.b64encode(bytearray(msg,"utf-8"))
sign = hmac.new(bytearray(secretKey,"utf-8"), msg=encodedMsg,
digestmod=hashlib.sha1).digest()
encodedSign =base64.b64encode(sign)
token = accessKey + ":" + encodedSign.decode(encoding='utf-8') + ":" + encodedMsg.decode(encoding='utf-8')
return token
token = create_token("hello world", "youraccessKey", "yoursecretKey")
print(str(token))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment