美文网首页
from Crypto.Cipher import AES 加

from Crypto.Cipher import AES 加

作者: 朝畫夕拾 | 来源:发表于2020-01-08 16:30 被阅读0次

    from  Crypto.Cipher  import AES

    import base64

    """AES加密算法"""

    #加密

    def  encryt(str, key):

        BS = AES.block_size

        pad =lambdas: s + (BS - len(s) % BS) * chr(BS - len(s) % BS)

        cipher = AES.new(key, AES.MODE_ECB,str)

        msg = cipher.encrypt(pad(str))

        msg = base64.encodestring(msg)

        return msg

    #解密

    def decrypt(enStr, key):

        unpad =lambdas: s[0:-ord(s[-1])]

        cipher = AES.new(key, AES.MODE_ECB)

        decryptByts = base64.decodestring(enStr)

        msg = cipher.decrypt(decryptByts)

        msg=unpad(msg.decode())

        return msg

    str="my name is maple"

    #此处的key的长度需要16位

    key="ffm1111111111111"res=encryt(str,key)print(res)

    pres=decrypt(res,key)print(pres)

    相关文章

      网友评论

          本文标题:from Crypto.Cipher import AES 加

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