Skip to content

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

@anxiangyipiao

Description

@anxiangyipiao

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}")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions