gomyck-tools 1.2.1__py3-none-any.whl → 1.2.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.
- ctools/api_result.py +0 -2
- ctools/cjson.py +5 -5
- ctools/date_utils.py +1 -1
- ctools/dict_wrapper.py +3 -1
- ctools/rsa.py +70 -0
- ctools/sm_tools.py +17 -4
- {gomyck_tools-1.2.1.dist-info → gomyck_tools-1.2.2.dist-info}/METADATA +1 -1
- {gomyck_tools-1.2.1.dist-info → gomyck_tools-1.2.2.dist-info}/RECORD +10 -10
- ctools/license.py +0 -37
- {gomyck_tools-1.2.1.dist-info → gomyck_tools-1.2.2.dist-info}/WHEEL +0 -0
- {gomyck_tools-1.2.1.dist-info → gomyck_tools-1.2.2.dist-info}/top_level.txt +0 -0
ctools/api_result.py
CHANGED
ctools/cjson.py
CHANGED
@@ -6,7 +6,7 @@ jsonpickle.set_preferred_backend('json')
|
|
6
6
|
jsonpickle.set_encoder_options('json', ensure_ascii=False)
|
7
7
|
jsonpickle.set_decoder_options('json')
|
8
8
|
|
9
|
-
def dumps(obj) -> str:
|
9
|
+
def dumps(obj, **kwargs) -> str:
|
10
10
|
"""
|
11
11
|
将对象转换为json字符串
|
12
12
|
:param obj: 对象
|
@@ -14,18 +14,18 @@ def dumps(obj) -> str:
|
|
14
14
|
"""
|
15
15
|
if obj is None: return None
|
16
16
|
if type(obj) == str: return obj
|
17
|
-
return f'{jsonpickle.encode(obj, unpicklable=False)}'
|
17
|
+
return f'{jsonpickle.encode(obj, unpicklable=False, make_refs=False, **kwargs)}'
|
18
18
|
|
19
|
-
def loads(json_str: str) -> dict:
|
19
|
+
def loads(json_str: str, **kwargs) -> dict:
|
20
20
|
"""
|
21
21
|
将json字符串转换为对象
|
22
22
|
:param json_str: json 字符串
|
23
23
|
:return: 对象
|
24
24
|
"""
|
25
|
-
return jsonpickle.decode(json_str)
|
25
|
+
return jsonpickle.decode(json_str, **kwargs)
|
26
26
|
|
27
27
|
def unify_to_str(json_str: str) -> str:
|
28
|
-
if not str_value_keys: return json_str
|
28
|
+
if not str_value_keys and len(str_value_keys) == 0: return json_str
|
29
29
|
obj = loads(json_str)
|
30
30
|
if isinstance(obj, list):
|
31
31
|
_handle_list(obj)
|
ctools/date_utils.py
CHANGED
@@ -30,7 +30,7 @@ def get_file_time():
|
|
30
30
|
获取 %Y-%m-%d %H:%M:%S 文件格式时间
|
31
31
|
:return:
|
32
32
|
"""
|
33
|
-
return time.strftime('%Y-%m-%d_%H-%M-%S', time.localtime(time.time()))
|
33
|
+
return time.strftime('%Y-%m-%d_%H-%M-%S-%s', time.localtime(time.time()))
|
34
34
|
|
35
35
|
def get_timestamp(offset=0):
|
36
36
|
return int(time.time() + offset)
|
ctools/dict_wrapper.py
CHANGED
@@ -6,7 +6,9 @@ __date__ = '2024/10/25 09:42'
|
|
6
6
|
class DictWrapper(dict):
|
7
7
|
def __getattr__(self, key):
|
8
8
|
res = self.get(key)
|
9
|
-
if
|
9
|
+
if res is None:
|
10
|
+
raise AttributeError(f"'{key}' not found in this Entity")
|
11
|
+
if isinstance(res, dict):
|
10
12
|
return DictWrapper(res)
|
11
13
|
return res
|
12
14
|
|
ctools/rsa.py
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
import base64
|
2
|
+
|
3
|
+
from Crypto.Cipher import PKCS1_OAEP
|
4
|
+
from Crypto.PublicKey import RSA
|
5
|
+
from Crypto.Signature import pkcs1_15
|
6
|
+
from Crypto.Hash import SHA256
|
7
|
+
|
8
|
+
from ctools import work_path, cjson
|
9
|
+
|
10
|
+
ENCRYPT_CHUNK_SIZE = 245
|
11
|
+
decrypt_CHUNK_SIZE = 512
|
12
|
+
|
13
|
+
def generate_rsa_keypair(bits=2048):
|
14
|
+
key = RSA.generate(bits)
|
15
|
+
private_key = key.export_key() # 导出私钥
|
16
|
+
public_key = key.publickey().export_key() # 导出公钥
|
17
|
+
with open("private_key.pem", "wb") as f:
|
18
|
+
f.write(private_key)
|
19
|
+
with open("public_key.pem", "wb") as f:
|
20
|
+
f.write(public_key)
|
21
|
+
|
22
|
+
def loadLicenseInfo(auth_code):
|
23
|
+
with open(work_path.get_app_path() + '/keys/license.key', 'r') as pri:
|
24
|
+
decrypt_message = decrypt(auth_code.strip(), pri.read())
|
25
|
+
return cjson.loads(decrypt_message)
|
26
|
+
|
27
|
+
# 加密函数
|
28
|
+
def encrypt(msg, public_key):
|
29
|
+
parts = b''
|
30
|
+
public_key = RSA.import_key(public_key)
|
31
|
+
cipher = PKCS1_OAEP.new(public_key)
|
32
|
+
for i in range(0, len(msg), ENCRYPT_CHUNK_SIZE):
|
33
|
+
parts += cipher.encrypt(msg[i:i + ENCRYPT_CHUNK_SIZE].encode())
|
34
|
+
encrypted_base64 = base64.b64encode(parts)
|
35
|
+
return encrypted_base64.decode()
|
36
|
+
|
37
|
+
# 解密函数
|
38
|
+
def decrypt(msg, private_key):
|
39
|
+
parts = b''
|
40
|
+
public_key = RSA.import_key(private_key)
|
41
|
+
cipher = PKCS1_OAEP.new(public_key)
|
42
|
+
encrypted_bytes = base64.b64decode(msg)
|
43
|
+
for i in range(0, len(encrypted_bytes), decrypt_CHUNK_SIZE):
|
44
|
+
parts += cipher.decrypt(encrypted_bytes[i:i + decrypt_CHUNK_SIZE])
|
45
|
+
return parts.decode()
|
46
|
+
|
47
|
+
# 验签
|
48
|
+
def verify_sign(msg, public_key, sign):
|
49
|
+
public_key = RSA.import_key(public_key)
|
50
|
+
hash_message = SHA256.new(msg.encode())
|
51
|
+
try:
|
52
|
+
pkcs1_15.new(public_key).verify(hash_message, base64.b64decode(sign.encode()))
|
53
|
+
return True
|
54
|
+
except Exception as e:
|
55
|
+
print('签名验证失败: {}'.format(e))
|
56
|
+
return False
|
57
|
+
|
58
|
+
# 签名
|
59
|
+
def sign_msg(msg, private_key):
|
60
|
+
private_key = RSA.import_key(private_key)
|
61
|
+
hash_message = SHA256.new(msg.encode())
|
62
|
+
signature = pkcs1_15.new(private_key).sign(hash_message)
|
63
|
+
return base64.b64encode(signature).decode()
|
64
|
+
|
65
|
+
|
66
|
+
# with open(work_path.get_current_path() + '/private_key.pem', 'r') as key:
|
67
|
+
# key = key.read()
|
68
|
+
# sign = sign_msg(key, key)
|
69
|
+
# with open(work_path.get_current_path() + '/public_key.pem', 'r') as pub:
|
70
|
+
# print(verify_sign(key, pub.read(), sign+'123'))
|
ctools/sm_tools.py
CHANGED
@@ -3,22 +3,35 @@ import base64
|
|
3
3
|
from gmssl import sm2, func
|
4
4
|
from gmssl.sm4 import CryptSM4, SM4_ENCRYPT, SM4_DECRYPT
|
5
5
|
|
6
|
-
sm2_crypt: sm2.CryptSM2
|
6
|
+
sm2_crypt: sm2.CryptSM2 = None
|
7
7
|
|
8
|
+
def init(private_key: str, public_key: str):
|
9
|
+
global sm2_crypt
|
10
|
+
if sm2_crypt is not None:
|
11
|
+
print('sm2 is already init!!!')
|
12
|
+
return
|
13
|
+
sm2_crypt = sm2.CryptSM2(private_key=private_key, public_key=public_key, asn1=True, mode=1)
|
8
14
|
|
9
15
|
def sign_with_sm2(sign_data: str) -> str:
|
10
|
-
|
16
|
+
if sm2_crypt is None: raise Exception('sm2 is not init!!!')
|
17
|
+
return sm2_crypt.sign_with_sm3(sign_data.encode('UTF-8'))
|
11
18
|
|
12
19
|
|
13
20
|
def verify_with_sm2(sign_val: str, sign_data: str) -> bool:
|
14
|
-
|
15
|
-
|
21
|
+
if sm2_crypt is None: raise Exception('sm2 is not init!!!')
|
22
|
+
try:
|
23
|
+
return sm2_crypt.verify_with_sm3(sign_val, sign_data.encode('UTF-8'))
|
24
|
+
except Exception as e:
|
25
|
+
print('签名验证失败: {}'.format(e))
|
26
|
+
return False
|
16
27
|
|
17
28
|
def encrypt_with_sm2(encrypt_data: str) -> str:
|
29
|
+
if sm2_crypt is None: raise Exception('sm2 is not init!!!')
|
18
30
|
return base64.b64encode(sm2_crypt.encrypt(encrypt_data.encode('UTF-8'))).decode('UTF-8')
|
19
31
|
|
20
32
|
|
21
33
|
def decrypt_with_sm2(encrypt_data: str) -> str:
|
34
|
+
if sm2_crypt is None: raise Exception('sm2 is not init!!!')
|
22
35
|
return sm2_crypt.decrypt(base64.b64decode(encrypt_data.encode('UTF-8'))).decode('UTF-8')
|
23
36
|
|
24
37
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
ctools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
2
|
ctools/aes_tools.py,sha256=ylUgyhlx7bNCTGrbWEZVwCObzYdJTQtwEc4ZMidL2Fo,563
|
3
|
-
ctools/api_result.py,sha256=
|
3
|
+
ctools/api_result.py,sha256=BLoJiTHFAIFRPCc4zer7NHTsRQFMY1TH-qmxSMk8iLU,1208
|
4
4
|
ctools/application.py,sha256=DcuSt2m8cDuSftx6eKfJ5gA6_F9dDlzkj0K86EG4F7s,15884
|
5
5
|
ctools/b64.py,sha256=_BdhX3p3-MaSSlU2wivN5qPxQfacR3VRBr1WC456tU0,194
|
6
6
|
ctools/bashPath.py,sha256=BCN_EhYzqvwsxYso81omMNd3SbEociwSOyb9kLvu8V4,337
|
@@ -9,14 +9,14 @@ ctools/bottle_webserver.py,sha256=8w1oj6_P09an6Pdnr5dH9ClBiD-A6k27IBCSvqVfcTs,25
|
|
9
9
|
ctools/bottle_websocket.py,sha256=wjsjKVE_tlon0hYfnzBT0Sis6yNPe318vKgTfzWYbfQ,1903
|
10
10
|
ctools/browser_element_tools.py,sha256=IFR_tWu5on0LxhuC_4yT6EOjwCsC-juIoU8KQRDqR7E,9952
|
11
11
|
ctools/call.py,sha256=BCr8wzt5qd70okv8IZn-9-EpjywleZgvA3u1vfZ_Kt8,1581
|
12
|
-
ctools/cjson.py,sha256=
|
12
|
+
ctools/cjson.py,sha256=g5OldDeD7bmdw_4NNNPfAREGXNplQxY_l9vtTz-UBTs,1331
|
13
13
|
ctools/ckafka.py,sha256=EiiGCFkSbq8yRjQKVjc2_V114hKb8fJAVIOks_XbQ3w,5944
|
14
14
|
ctools/compile_tools.py,sha256=Nybh3vnkurIKnPnubdYzigjnzFu4GaTMKPvqFdibxmE,510
|
15
15
|
ctools/console.py,sha256=EZumuyynwteKUhUxB_XoulHswDxHd75OQB34RiZ-OBM,1807
|
16
16
|
ctools/cron_lite.py,sha256=f9g7-64GsCxcAW-HUAvT6S-kooScl8zaJyqwHY-X_rE,8308
|
17
17
|
ctools/database.py,sha256=7YzkO2tzV1KUQLHND8g9PkQwTyGd3clhgPiZ5SbC-HA,5447
|
18
|
-
ctools/date_utils.py,sha256
|
19
|
-
ctools/dict_wrapper.py,sha256=
|
18
|
+
ctools/date_utils.py,sha256=qkIvn2TGQ97vUw2ppBfHE7IyCUqg0s1FzrB0BJAsaBo,868
|
19
|
+
ctools/dict_wrapper.py,sha256=6lZUyHomdn5QdjQTg7EL1sC_I6tOlh8ofMRQT3XGQjM,398
|
20
20
|
ctools/douglas_rarefy.py,sha256=43WRjGGsQ_o1yPEXypA1Xv_yuo90RVo7qaYGRslx5gQ,4890
|
21
21
|
ctools/download_tools.py,sha256=oJbG12Hojd0J17sAlvMU480P3abi4_AB9oZkEBGFPuo,1930
|
22
22
|
ctools/enums.py,sha256=QbHa3j7j4-BDdwaga5Y0nYfA2uNSVJDHumYdIZdKVkM,118
|
@@ -26,7 +26,6 @@ ctools/html_soup.py,sha256=rnr8M3gn3gQGo-wNaNFXDjdzp8AAkv9o4yqfIIfO-zw,1567
|
|
26
26
|
ctools/http_utils.py,sha256=dG26aci1_YxAyKwYqMKFw4wZAryLkDyvnQ3hURjB6Lk,768
|
27
27
|
ctools/images_tools.py,sha256=TapXYCPqC7GesgrALecxxa_ApuT_dxUG5fqQIJF2bNY,670
|
28
28
|
ctools/imgDialog.py,sha256=zFeyPmpnEn9Ih7-yuJJrePqW8Myj3jC9UYMTDk-umTs,1385
|
29
|
-
ctools/license.py,sha256=0Kh7lXL7LD1PQqyijHajFL0GbmZGNB88PA2WskbQn_s,1066
|
30
29
|
ctools/metrics.py,sha256=vq9Fnq2fhmhS4yoHS4gO7ArKS033Eou8vpA779Uue0I,4414
|
31
30
|
ctools/mqtt_utils.py,sha256=ZWSZiiNJLLlkHF95S6LmRmkYt-iIL4K73VdN3b1HaHw,10702
|
32
31
|
ctools/obj.py,sha256=GYS1B8NyjtUIh0HlK9r8avC2eGbK2SJac4C1CGnfGhI,479
|
@@ -35,9 +34,10 @@ ctools/plan_area_tools.py,sha256=pySri43bVfkHjzlKujML-Nk8B3QLxuYv5KJMha-MLmU,331
|
|
35
34
|
ctools/process_pool.py,sha256=1TuZySUbQjgYYcuwis54DIwQTimWvTLNahSra7Ia8Ps,951
|
36
35
|
ctools/pty_tools.py,sha256=KI3dOyv2JLZmU1VfD1aLMq9r9d5VCu3TdtcezZayBEI,1622
|
37
36
|
ctools/resource_bundle_tools.py,sha256=wA4fmD_ZEcrpcvUZKa60uDDX-nNQSVz1nBh0A2GVuTI,3796
|
37
|
+
ctools/rsa.py,sha256=c0q7oStlpSfTxmn900XMDjyOGS1A7tVsUIocr0nL2UI,2259
|
38
38
|
ctools/screenshot_tools.py,sha256=KoljfgqW5x9aLwKdIfz0vR6v-fX4XjE92HudkDxC2hE,4539
|
39
39
|
ctools/sign.py,sha256=JOkgpgsMbk7T3c3MOj1U6eiEndUG9XQ-uIX9e615A_Y,566
|
40
|
-
ctools/sm_tools.py,sha256=
|
40
|
+
ctools/sm_tools.py,sha256=CDfgupqs_nrZs-135ZvDu6QIx4aamJVdg7vuLs9_0yw,1678
|
41
41
|
ctools/snow_id.py,sha256=hYinnRN-aOule4_9vfgXB7XnsU-56cIS3PhzAwWBc5E,2270
|
42
42
|
ctools/strDiff.py,sha256=QUtXOfsRLTFozH_zByqsC39JeuG3eZtrwGVeLyaHYUI,429
|
43
43
|
ctools/string_tools.py,sha256=p_O3HiqlHCgzJVXHUeeDYZK2_WrqetD0eYijQFXWkGg,1938
|
@@ -51,7 +51,7 @@ ctools/wordFill.py,sha256=dB1OLt6GLmWdkDV8H20VWbJmY4ggNNI8iHD1ocae2iM,875
|
|
51
51
|
ctools/word_fill.py,sha256=xeo-P4DOjQUqd-o9XL3g66wQrE2diUPGwFywm8TdVyw,18210
|
52
52
|
ctools/word_fill_entity.py,sha256=eX3G0Gy16hfGpavQSEkCIoKDdTnNgRRJrFvKliETZK8,985
|
53
53
|
ctools/work_path.py,sha256=i4MTUobqNW2WMrT3mwEC_XYQ0_IhFmKoNpTX2W6A8Tc,1680
|
54
|
-
gomyck_tools-1.2.
|
55
|
-
gomyck_tools-1.2.
|
56
|
-
gomyck_tools-1.2.
|
57
|
-
gomyck_tools-1.2.
|
54
|
+
gomyck_tools-1.2.2.dist-info/METADATA,sha256=CzDE6NMxpgyVbq_51yDC0b4mEE0IBkcuNI85aat7t7M,1004
|
55
|
+
gomyck_tools-1.2.2.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
|
56
|
+
gomyck_tools-1.2.2.dist-info/top_level.txt,sha256=-MiIH9FYRVKp1i5_SVRkaI-71WmF1sZSRrNWFU9ls3s,7
|
57
|
+
gomyck_tools-1.2.2.dist-info/RECORD,,
|
ctools/license.py
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
import base64
|
2
|
-
|
3
|
-
from Crypto.Cipher import PKCS1_OAEP
|
4
|
-
from Crypto.PublicKey import RSA
|
5
|
-
|
6
|
-
from ctools import work_path, cjson
|
7
|
-
|
8
|
-
ENCRYPT_CHUNK_SIZE = 245
|
9
|
-
decrypt_CHUNK_SIZE = 512
|
10
|
-
|
11
|
-
|
12
|
-
# 加密函数
|
13
|
-
def encrypt(msg, public_key):
|
14
|
-
parts = b''
|
15
|
-
private_key = RSA.import_key(public_key)
|
16
|
-
cipher = PKCS1_OAEP.new(private_key)
|
17
|
-
for i in range(0, len(msg), ENCRYPT_CHUNK_SIZE):
|
18
|
-
parts += cipher.encrypt(msg[i:i + ENCRYPT_CHUNK_SIZE].encode())
|
19
|
-
encrypted_base64 = base64.b64encode(parts)
|
20
|
-
return encrypted_base64.decode()
|
21
|
-
|
22
|
-
|
23
|
-
# 解密函数
|
24
|
-
def decrypt(msg, private_key):
|
25
|
-
parts = b''
|
26
|
-
public_key = RSA.import_key(private_key)
|
27
|
-
cipher = PKCS1_OAEP.new(public_key)
|
28
|
-
encrypted_bytes = base64.b64decode(msg)
|
29
|
-
for i in range(0, len(encrypted_bytes), decrypt_CHUNK_SIZE):
|
30
|
-
parts += cipher.decrypt(encrypted_bytes[i:i + decrypt_CHUNK_SIZE])
|
31
|
-
return parts.decode()
|
32
|
-
|
33
|
-
|
34
|
-
def loadLicenseInfo(auth_code):
|
35
|
-
with open(work_path.get_app_path() + '/keys/license.key', 'r') as pri:
|
36
|
-
decrypt_message = decrypt(auth_code.strip(), pri.read())
|
37
|
-
return cjson.loads(decrypt_message)
|
File without changes
|
File without changes
|