python 使用AES加密16位

def Login(username, password):
    key = '1234567890123456'  # 加密秘钥要设置16位
    length = 16
    count = len(password.encode('utf-8'))
    #如果 被加密参数不是16的倍数那就补足为16的倍数
    if (count % length != 0):
        add = length - (count % length)
    else:
        add = 0
    #用1补足
    PW = password + ('\1' * add)

    # 初始化加密器
    aes = AES.new(str.encode(key), AES.MODE_ECB)
    PW = str(base64.b64encode(aes.encrypt(str.encode(PW))), encoding='utf-8')
    print(PW)

 

posted @ 2020-09-29 09:32  不屈的鸣人  阅读(905)  评论(0编辑  收藏  举报