-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
1,520 additions
and
43 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import base64 | ||
from Crypto.Cipher import AES | ||
from Crypto.Util.Padding import pad | ||
import json | ||
|
||
# https://blog.csdn.net/qq_45664055/article/details/123348485 | ||
class EncryptDate: | ||
def __init__(self, key): | ||
# 初始化密钥 | ||
self.key = key | ||
# 初始化数据块大小 | ||
self.length = AES.block_size | ||
# 初始化AES,ECB模式的实例 | ||
self.aes = AES.new(self.key.encode("utf-8"), AES.MODE_ECB) | ||
# 截断函数,去除填充的字符 | ||
self.unpad = lambda date: date[0:-ord(date[-1])] | ||
|
||
def fill_method(self, aes_str): | ||
'''pkcs7补全''' | ||
pad_pkcs7 = pad(aes_str.encode('utf-8'), AES.block_size, style='pkcs7') | ||
|
||
return pad_pkcs7 | ||
|
||
def encrypt(self, encrData): | ||
# 加密函数,使用pkcs7补全 | ||
res = self.aes.encrypt(self.fill_method(encrData)) | ||
# 转换为base64 | ||
msg = str(base64.b64encode(res), encoding="utf-8") | ||
|
||
return msg | ||
|
||
def decrypt(self, decrData): | ||
# base64解码 | ||
res = base64.decodebytes(decrData.encode("utf-8")) | ||
# 解密函数 | ||
msg = self.aes.decrypt(res).decode("utf-8") | ||
|
||
return self.unpad(msg) | ||
|
||
_e = EncryptDate(key="#14ljk_!\]&0U<'(") | ||
|
||
def parse_163key(key): | ||
return json.loads(_e.decrypt(key)[6:]) | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pycryptodome |
Oops, something went wrong.