zoukankan      html  css  js  c++  java
  • AEE加密解密

     from Crypto.Cipher import AES
    from binascii import b2a_hex, a2b_hex


    class AesHandler(object):
        def __init__(self, key, iv, mode):
            self.key = key
            self.iv = iv
            self.mode = mode
            self.BS = AES.block_size  # Size of a data block (in bytes) 16
            self.pad = lambda s: s + (self.BS - len(s) % self.BS) * chr(
                self.BS - len(s) % self.BS)
            self.unpad = lambda s: s[0:-ord(s[-1])]

        def encrypt(self, text):
            text = self.pad(text)
            cipher = AES.new(self.key, self.mode, self.iv)
            cipher_text = cipher.encrypt(text)
            return b2a_hex(cipher_text)

        def decrypt(self, text):
            cipher = AES.new(self.key, self.mode, self.iv)
            plain_text = cipher.decrypt(a2b_hex(text))
            return self.unpad(plain_text.rstrip(''))


    if __name__ == '__main__':
        key = 'zhyh37MmA67Ato%Z'
        iv = 'Q@p%TLoLCEMollMq'
        aes = AesHandler(key, iv, AES.MODE_CBC)
        e = aes.encrypt("in the wifi.com")
        print "加密:", e
        d = aes.decrypt(e)
        print "解密:", d
  • 相关阅读:
    php数组转换成js可用的数组的两种方式
    常用正则表达式--------------[拿把小刀,强大自己]
    AngularJs 相应回车事件
    常见的关系型数据库和非关系型数据库及其区别
    CMDB资产采集
    GB和GiB的区别
    python枚举详解
    python保留两位小数
    详解TCP三握四挥
    npm run dev 和 npm run serve
  • 原文地址:https://www.cnblogs.com/xiaoyaowuming/p/6600352.html
Copyright © 2011-2022 走看看