Skip to content

参考资料:成都市中小学教师继续教育网登录密码加密 #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
anxiangyipiao opened this issue Apr 14, 2025 · 0 comments

Comments

@anxiangyipiao
Copy link

from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
import binascii
import base64

def encrypt_data(userid):
# 密钥和初始化向量设置
secret_passphrase = '01aaa85c-c60d-43f6-bf6a-cdaa344d'
key = secret_passphrase.encode('utf-8')
iv = "1234567890000000".encode('utf-8')

# 确保密钥长度为32位(AES-256)
if len(key) < 32:
    key = key.ljust(32, b'\0')
elif len(key) > 32:
    key = key[:32]

# 确保IV长度为16位(AES块大小)
if len(iv) != 16:
    iv = iv[:16] if len(iv) > 16 else iv.ljust(16, b'\0')

# 加密用户ID
cipher = AES.new(key, AES.MODE_CBC, iv)
encrypted_userid = cipher.encrypt(pad(userid.encode('utf-8'), AES.block_size))

# 返回加密后的十六进制字符串
return binascii.hexlify(encrypted_userid).decode('utf-8')

使用示例

if name == "main":

userid = "11111111111"

encrypted_userid = encrypt_data(userid)

print(f"Encrypted User ID: {encrypted_userid}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant