安装包
pip install pycryptodome==3.8.1
直接上代码(加密类Encrypts, 解密类Decrypts)
import hashlib
import os
from Crypto.Cipher import AES
import base64
from binascii import b2a_hex, a2b_hex
from Crypto import Random
from Crypto.Cipher import PKCS1_v1_5 as Cipher_pkcs1_v1_5
from Crypto.PublicKey import RSA
class Encrypts:
"""MD5 base64 AES RSA 四种加密方法"""
def __init__(self):
self.aes_mode = AES.MODE_ECB # AES加密模式
self.aes_key_size = 256 # AES秘钥,随机数值
self.rsa_count = 2048 # RSA秘钥对,随机数值
def md5_encrypt(plaintext):
""" MD5加密
:param plaintext: 需要加密的内容
:return: encrypt_str密文
"""
h1 = hashlib.md5() # 创建md5对象
h1.update(plaintext.encode(encoding='utf-8&#