Python加密模块-pycryptodome

这个模块可以避开Pycrypto安装时带来的一系列包依赖问题.

安装命令:

pip install pycryptodome

使用实例:

from Crypto.Cipher import AES

key = b'encrypto'
passwd = b'mypassword'

#加密内容需要长达16位字符,所以进行空格拼接
def pad(passwd):
    while len(passwd) % 16 != 0:
        passwd += b' '
    return passwd

#加密秘钥需要长达16位字符,所以进行空格拼接
def pad_key(key):
    while len(key)%16 != 0:
        key += b' '
    return key

aes = AES.new(pad_key(key), AES.MODE_ECB)

encrypted_text = aes.encrypt(pad(passwd))
print(encrypted_text)

de = str(aes.decrypt(encrypted_text),encoding='utf-8', errors= 'ignore')
print(de)

结果:
  b'xb9cxaf14xc9xa3x97x18xba@&xcfx19<Y'
  mypassword

  

原文地址:https://www.cnblogs.com/konglinqingfeng/p/9582763.html