Created
December 8, 2015 03:41
-
-
Save optman/7abfb399f3d56134fdef to your computer and use it in GitHub Desktop.
baofeng cloud token
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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