AES加密

作者: aq_wzj | 来源:发表于2019-01-14 16:14 被阅读0次
    from Crypto.Cipher import AES
    
    # ==============加密=============
    def encrypt(massage):
        key = b'dfdsdfsasdfdsdfs'
        cipher = AES.new(key, AES.MODE_CBC, key)
        ba_data = bytearray(massage, encoding='utf-8')
        v1 = len(ba_data)
        v2 = v1 % 16
        if v2 == 0:
            v3 = 16
        else:
            v3 = 16 - v2
        for i in range(v3):
            ba_data.append(v3)
        msg = cipher.encrypt(ba_data)
        return msg
    
    # ==============解密==============
    def decrypt(msg):
        from Crypto.Cipher import AES
        key = b'dfdsdfsasdfdsdfs'
        cipher = AES.new(key, AES.MODE_CBC, key)
        result = cipher.decrypt(msg)
        data = result[0:-result[-1]]
        return str(data,encoding='utf-8')
    
    msg = encrypt('这里是要加密的字符串')
    
    res = decrypt(msg)
    print(res)
    

    相关文章

      网友评论

          本文标题:AES加密

          本文链接:https://www.haomeiwen.com/subject/dbhjdqtx.html