[Python]模拟登陆CHD密码加密部分

[Python]模拟登陆CHD密码加密部分

仅供学习,请勿用于违法用途

输入密码和加密Key,并使用encrypt(data, key)即可加密。


chars = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678"
charsLen = len(chars)
def rds(len):
    ret = ""
    for i in range(len):
        ret = ret + str(chars[random.randint(0, charsLen - 1)])
    return ret
def pad(text):
    count = len(text)
    fillSize = AES.block_size - (count % AES.block_size)
    ret = text + chr(fillSize) * fillSize
    return ret
def aes_encry(data, key, iv):
    key = key.replace(r"(^\s+)|(\s+$)", "")
    aes = AES.new(key.encode("utf-8"), AES.MODE_CBC, iv.encode("utf-8"))
    ret = aes.encrypt(pad(data).encode("utf-8"))
    return base64.b64encode(ret).decode("utf-8")
def encrypt(data, key):
    iv = rds(16)
    data = rds(64) + data
    return aes_encry(data, key, iv)