AES加密解密
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad
import base64
# 加密数据 AES-128 16位字节
key = b'1111111111111111'
# key = '1111111111111111'.encode()
iv = b'1111111111111111'
# 创建实例
aes = AES.new(key, AES.MODE_CBC, iv)
# 要加密的内容
text = b"I am zbb"
# 填充数据16
data = pad(text, AES.block_size)
# 加密
encrypted = aes.encrypt(data)
# 处理编码
base64_data = base64.b64encode(encrypted).decode('utf-8')
print(base64_data)
#############################解密 上面和虾米分开
# 处理解码
new_data = base64.b64decode('BGfPk3vh6JNJKbdz4rdvIQ==')
# 解密
data = aes.decrypt(new_data)
data = unpad(data, 16).decode('utf-8')
print(data)
#############爬虫案例
import json
import time
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad
import base64
import requests
cookies = {
'SECKEY_ABVK': '4FEyWha4eeyQRebV3Rk5zI+GJ2wPbhOvft92A0pnZOM2rPb4y/7LT74yIAqkGHtC1SJDxiTO0DVfwxALhYNENA%3D%3D',
'Hm_lvt_6cd598ca665714ffcd8aca3aafc5e0dc': '1713113457',
'Hm_lpvt_6cd598ca665714ffcd8aca3aafc5e0dc': '1713113457',
'BMAP_SECKEY': '4FEyWha4eeyQRebV3Rk5zI-GJ2wPbhOvft92A0pnZOOJ6AQsDtC72oCm6kVt3nzu0h2wwN3496nmDWjq0gceSvHIyxIoM2MAuG9cKiJn7mpYRezaNB3cgCujWz1mvOUTfwV00H0nFrmyzuQ_QDX5Y75Ny9QgpmEzfm6KIqeEw8BDh2BheEB7aOsbMRNYBp_UzQb1G8R3ta5MREFaspIypA',
'PHPSESSID': 'ab5civinlpujapg5lr4beumlne',
}
headers = {
'Accept': '*/*',
'Accept-Language': 'zh-CN,zh;q=0.9',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
'Content-Type': 'application/json; charset=UTF-8',
# 'Cookie': 'SECKEY_ABVK=4FEyWha4eeyQRebV3Rk5zI+GJ2wPbhOvft92A0pnZOM2rPb4y/7LT74yIAqkGHtC1SJDxiTO0DVfwxALhYNENA%3D%3D; Hm_lvt_6cd598ca665714ffcd8aca3aafc5e0dc=1713113457; Hm_lpvt_6cd598ca665714ffcd8aca3aafc5e0dc=1713113457; BMAP_SECKEY=4FEyWha4eeyQRebV3Rk5zI-GJ2wPbhOvft92A0pnZOOJ6AQsDtC72oCm6kVt3nzu0h2wwN3496nmDWjq0gceSvHIyxIoM2MAuG9cKiJn7mpYRezaNB3cgCujWz1mvOUTfwV00H0nFrmyzuQ_QDX5Y75Ny9QgpmEzfm6KIqeEw8BDh2BheEB7aOsbMRNYBp_UzQb1G8R3ta5MREFaspIypA; PHPSESSID=ab5civinlpujapg5lr4beumlne',
'Origin': 'https://www.maomaozu.com',
'Pragma': 'no-cache',
'Referer': 'https://www.maomaozu.com/',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
'sec-ch-ua': '"Chromium";v="122", "Not(A:Brand";v="24", "Google Chrome";v="122"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
}
# 加密数据 AES-128 16位字节
# 要加密的内容
for page in range(1, 5):
text = {"Type": 0,
"page": page,
"expire": 1713114839095}
text = json.dumps(text).encode('utf-8')
# 填充数据16
data = pad(text, AES.block_size)
key = '55b3b62613aef1a0'.encode()
iv = key
# 创建实例
aes = AES.new(key, AES.MODE_CBC, iv)
# 加密
encrypted = aes.encrypt(data)
# 处理编码
base64_data = base64.b64encode(encrypted).decode('utf-8')
# print(base64_data)
response = requests.post('https://www.maomaozu.com/index/build.json', cookies=cookies, headers=headers,
data=base64_data)
#############################解密 上面和虾米分开
key = '0a1fea31626b3b55'.encode()
iv = key
# 创建实例
aes = AES.new(key, AES.MODE_CBC, iv)
# 处理解码
new_data = base64.b64decode(response.text)
# 解密
data = aes.decrypt(new_data)
data = unpad(data, 16).decode('utf-8')
print(data)
time.sleep(2)
# 关键字搜索 路径搜索 方法搜索decrypt(
热爱技术,享受生活,感谢推荐!