python 3des ECB加密解密

# -*- coding: utf-8 -*-''' 
import base64
import pyDes

def encrypt_3des(clear_text, key):    
    clear_text_byte = clear_text.encode('utf-8')
    key_byte = key.encode('utf-8')
    key_byte = key_byte.ljust(24, "\0".encode('utf-8'))
    if len(key_byte) > 24:
        key_byte = key_byte[:24]

    k = pyDes.triple_des(key_byte, pyDes.ECB, IV = None, pad = None, padmode = pyDes.PAD_PKCS5)
    d = k.encrypt(clear_text_byte)

    return base64.b64encode(d).decode('utf-8')

def decrypt_3des(data, key):    
    data_byte = base64.b64decode(data.encode('utf-8'))
    key_byte = key.encode('utf-8')
    key_byte = key_byte.ljust(24, "\0".encode('utf-8'))
    if len(key_byte) > 24:
        key_byte = key_byte[:24]
    k = pyDes.triple_des(key_byte, pyDes.ECB, IV = None, pad = None, padmode = pyDes.PAD_PKCS5)
    d = k.decrypt(data_byte)

    return d.decode('utf-8')