issaocean commited on
Commit
27cd7d6
·
verified ·
1 Parent(s): 1ab790c

Update bearer_token.py

Browse files
Files changed (1) hide show
  1. bearer_token.py +2 -2
bearer_token.py CHANGED
@@ -20,7 +20,7 @@ class BearerTokenGenerator:
20
  secret_key = bytes(ast.literal_eval(secret_key_str))
21
 
22
  timestamp = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
23
- prefix = f"POST:{path}:{timestamp}\n".encode()
24
  to_sign = prefix + body.encode()
25
 
26
  signature = BearerTokenGenerator.generate_signature(to_sign, secret_key)
@@ -32,4 +32,4 @@ class BearerTokenGenerator:
32
  @staticmethod
33
  def generate_signature(to_sign: bytes, secret_key: bytes) -> str:
34
  h = hmac.new(secret_key, to_sign, hashlib.sha256)
35
- return base64.b64encode(h.digest()).decode()
 
20
  secret_key = bytes(ast.literal_eval(secret_key_str))
21
 
22
  timestamp = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
23
+ prefix = f"POST:{path}:{timestamp}".encode() # 移除换行符
24
  to_sign = prefix + body.encode()
25
 
26
  signature = BearerTokenGenerator.generate_signature(to_sign, secret_key)
 
32
  @staticmethod
33
  def generate_signature(to_sign: bytes, secret_key: bytes) -> str:
34
  h = hmac.new(secret_key, to_sign, hashlib.sha256)
35
+ return base64.b64encode(h.digest()).decode()