53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
from Crypto.Cipher import AES
|
|
from Crypto.Util.Padding import pad, unpad
|
|
import base64
|
|
import hashlib
|
|
|
|
# 加密函数
|
|
def encrypt(plain_text, key):
|
|
key = hashlib.sha256(key.encode('utf-8')).digest()[:16] # 保证密钥为16字节
|
|
cipher = AES.new(key, AES.MODE_CBC) # CBC模式
|
|
ct_bytes = cipher.encrypt(pad(plain_text.encode('utf-8'), AES.block_size))
|
|
iv = base64.b64encode(cipher.iv).decode('utf-8')
|
|
ct = base64.b64encode(ct_bytes).decode('utf-8')
|
|
return iv + ct # 返回初始化向量和密文
|
|
|
|
# 解密函数
|
|
def decrypt(cipher_text, key):
|
|
key = hashlib.sha256(key.encode('utf-8')).digest()[:16] # 保证密钥为16字节
|
|
iv = base64.b64decode(cipher_text[:24]) # 提取初始化向量
|
|
ct = base64.b64decode(cipher_text[24:]) # 提取密文
|
|
cipher = AES.new(key, AES.MODE_CBC, iv)
|
|
decrypted = unpad(cipher.decrypt(ct), AES.block_size)
|
|
return decrypted.decode('utf-8')
|
|
|
|
# 使用示例
|
|
key = 'thisisaverysecret' # 16字节的密钥
|
|
phone_number = '8616533817456'
|
|
|
|
|
|
|
|
# 使用示例
|
|
key = 'thisisaverysecret' # 16字节的密钥
|
|
|
|
if __name__ == '__main__':
|
|
|
|
with open('phones.txt', 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
|
|
tasks = [] # 创建任务列表
|
|
lines = content.split('\n')
|
|
|
|
n = 0
|
|
for _, line in enumerate(lines):
|
|
print(line)
|
|
|
|
phone_number =line
|
|
|
|
# 加密
|
|
encrypted = encrypt(phone_number, key)
|
|
# print("Encrypted:", encrypted)
|
|
|
|
print(f"http://205.198.72.45:5000/get_verification_code?token={encrypted}")
|
|
|