pycrypto [加密]

    # https://github.com/dlitz/pycrypto
    SHA256  # 不可逆散列算法加密
        from Crypto.Hash import SHA256
        hash = SHA256.new()
        hash.update('message')
        hash.digest()

    AES     # 可逆加密,需要密钥
        from Crypto.Cipher import AES
        obj = AES.new('This is a key123', AES.MODE_CBC, 'This is an IV456')
        message = "The answer is no"
        ciphertext = obj.encrypt(message)
        ciphertext
        '\xd6\x83\x8dd!VT\x92\xaa`A\x05\xe0\x9b\x8b\xf1'
        obj2 = AES.new('This is a key123', AES.MODE_CBC, 'This is an IV456')
        obj2.decrypt(ciphertext)
        'The answer is no'
文档更新时间: 2018-11-21 17:32   作者:RuM