当前位置:   article > 正文

利用pycrypto处理AES加密解密_pycryptodomeaes mode_gcm解密文件

pycryptodomeaes mode_gcm解密文件

代码如下:

  1. from binascii import b2a_hex, a2b_hex
  2. from urllib import unquote
  3. from Crypto.Cipher import AES
  4. from Padding import appendSpacePadding
  5. class AesHandler(object):
  6. def __init__(self, **kwargs):
  7. """
  8. key,id是30环境A0008的
  9. """
  10. self.key = kwargs.get("key", "!I50#LSSciCx&q6E")
  11. self.iv = kwargs.get('iv', "$t%s%12#2b474pXF")
  12. self.mode = AES.MODE_CBC
  13. self.BS = AES.block_size
  14. def encrypt(self, text):
  15. text = appendSpacePadding(text)
  16. cipher = AES.new(self.key, self.mode, self.iv)
  17. cipher_text = cipher.encrypt(text)
  18. return b2a_hex(cipher_text)
  19. def decrypt(self, text):
  20. cipher = AES.new(self.key, self.mode, self.iv)
  21. plain_text = cipher.decrypt(a2b_hex(text))
  22. return unquote(plain_text)
223916_bL9y_2663968.jpg
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
  

闽ICP备14008679号