xtn-tools-pro 1.0.0.7.1__py3-none-any.whl → 1.0.0.7.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,8 +8,11 @@
8
8
  # --------------------------------------------------------------------------------------------------
9
9
  # 2024/5/13 xiatn V00.01.000 新建
10
10
  # --------------------------------------------------------------------------------------------------
11
+ import jwt
11
12
  import base64
12
13
  import hashlib
14
+ import secrets
15
+ import datetime
13
16
 
14
17
 
15
18
  def get_md5_32(s: str, is_upper=False):
@@ -117,5 +120,33 @@ def get_base64_encode(s: str):
117
120
  return encoded_string
118
121
 
119
122
 
123
+ def generate_bearer_token(secret_key, expiration=0, algorithm='HS256', **kwargs):
124
+ """
125
+ 生成 Bearer Token
126
+ :param secret_key: 用于加密的密钥
127
+ :param expiration: 过期时间戳,0则表示不过期
128
+ :param algorithm: 使用的加密算法(默认是 HS256)HS256、HS384、HS512
129
+ :param kwargs: 其他自定义的 Token 数据
130
+ :return: 生成的 Bearer Token
131
+ """
132
+ payload = {
133
+ **kwargs # 将其他参数添加到 payload
134
+ }
135
+ if expiration:
136
+ payload['exp'] = expiration
137
+
138
+ token = jwt.encode(payload, secret_key, algorithm=algorithm)
139
+ return token
140
+
141
+
142
+ def generate_secret_key(length=32):
143
+ """
144
+ 生成一个随机的 secret key
145
+ :param length: key 的长度,默认为 32
146
+ :return: 生成的 secret key
147
+ """
148
+ return secrets.token_hex(length)
149
+
150
+
120
151
  if __name__ == '__main__':
121
152
  print(get_base64_encode(''))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xtn-tools-pro
3
- Version: 1.0.0.7.1
3
+ Version: 1.0.0.7.2
4
4
  Summary: xtn 开发工具
5
5
  Author: xtn
6
6
  Author-email: czw011122@gmail.com
@@ -15,5 +15,6 @@ Requires-Dist: dbutils
15
15
  Requires-Dist: colorlog
16
16
  Requires-Dist: requests
17
17
  Requires-Dist: Faker
18
+ Requires-Dist: PyJWT
18
19
 
19
20
  xtnkk-tools
@@ -14,15 +14,15 @@ xtn_tools_pro/task_pro/go_fun.py,sha256=hWEt2uJ9FCvJH7PhVZttS-11A7J6zbRKwX7c5YLY
14
14
  xtn_tools_pro/task_pro/go_fun_v2.py,sha256=SgcXgtEBGSVL1V2LyqO0z8Md2H8JZxucYrLLIwqtiLM,18489
15
15
  xtn_tools_pro/task_pro/go_fun_v3.py,sha256=wPd7LFQlDhLH-5SIlq_1k8og5oW6KWeY6g3QvmZSFSU,16013
16
16
  xtn_tools_pro/utils/__init__.py,sha256=I1_n_NP23F2lBqlF4EOlnOdLYxM8M4pbn63UhJN1hRE,418
17
- xtn_tools_pro/utils/crypto.py,sha256=RZ5AET4udlraACWMeNF-17JiZ2R6Ahb47_j4tjkV7LE,3190
17
+ xtn_tools_pro/utils/crypto.py,sha256=oyzFqWum_oimUtzhfVCELQhdMjxDbLu-nOWfcNmazcc,4087
18
18
  xtn_tools_pro/utils/file_utils.py,sha256=VfdIxog4s1UW5NpKkCvQsUs9qHjLoNCnstZbnftkT4w,2046
19
19
  xtn_tools_pro/utils/helpers.py,sha256=H-a3gnahIah3kJqyKzzKlPWtVQYcFlJncz2rAfBqIiw,4444
20
20
  xtn_tools_pro/utils/log.py,sha256=m0WtTWkkwtrki1ftP8vCDR8bMfK2gcfUGx5J2x2IlLQ,10138
21
21
  xtn_tools_pro/utils/retry.py,sha256=0wjHsR5DBBKpv4naMfxiky8kprrZes4WURIfFQ4H708,1657
22
22
  xtn_tools_pro/utils/sql.py,sha256=EAKzbkZP7Q09j15Gm6o0_uq0qgQmcCQT6EAawbpp4v0,6263
23
23
  xtn_tools_pro/utils/time_utils.py,sha256=TUtzG61PeVYXhaQd6pBrXAdlz7tBispNIRQRcGhE2No,4859
24
- xtn_tools_pro-1.0.0.7.1.dist-info/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
- xtn_tools_pro-1.0.0.7.1.dist-info/METADATA,sha256=Yl6AU8kAvrr4nKEBgCHpLCJbOXtZ7UksCEF7XU-Gtuo,455
26
- xtn_tools_pro-1.0.0.7.1.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
27
- xtn_tools_pro-1.0.0.7.1.dist-info/top_level.txt,sha256=jyB3FLDEr8zE1U7wHczTgIbvUpALhR-ULF7RVEO7O2U,14
28
- xtn_tools_pro-1.0.0.7.1.dist-info/RECORD,,
24
+ xtn_tools_pro-1.0.0.7.2.dist-info/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
+ xtn_tools_pro-1.0.0.7.2.dist-info/METADATA,sha256=3yoxlnRP7RmdnMWzkHg8OpenKAmOWzzHAZAkLXbKKsk,477
26
+ xtn_tools_pro-1.0.0.7.2.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
27
+ xtn_tools_pro-1.0.0.7.2.dist-info/top_level.txt,sha256=jyB3FLDEr8zE1U7wHczTgIbvUpALhR-ULF7RVEO7O2U,14
28
+ xtn_tools_pro-1.0.0.7.2.dist-info/RECORD,,