AES解密脚本(Python)

# coding=utf-8
from M2Crypto.EVP import Cipher
from M2Crypto import m2  
from M2Crypto import util  
import urllib
import sys
import base64
import binascii
import Crypto
import Crypto.Random
import array
from Crypto.Cipher import AES  
ENCRYPT_OP = 1 # 加密操作  
DECRYPT_OP = 0 # 解密操作  
#print Crypto.Random.OSRNG.posix.new().read(AES.block_size) 
iv = '\0' * 16 # 初始化变量,对于aes_128_ecb算法无用  
iv_arr=b'\x01\x01\x0b\x05\x04\x0f\x07\x09\x17\x03\x01\x06\x08\x0c\x0d\x5b'
iv=iv_arr
PRIVATE_KEY = 'mymiyao' # 密钥
  
def Encrypt(data):  
  '使用aes_128_ecb算法对数据加密'  
  cipher = Cipher(alg = 'aes_128_cbc', key = PRIVATE_KEY, iv = iv, op = ENCRYPT_OP)  
  buf = cipher.update(data)  
  buf = buf + cipher.final()  
  del cipher  
  # 将明文从字节流转为16进制  
  output = ''  
  for i in buf:  
    output += '%02X' % (ord(i))  
  return output  
  
def Decrypt(data):  
  '使用aes_128_ecb算法对数据解密'  
  # 将密文从16进制转为字节流  
  data = util.h2b(data)  
  cipher = Cipher(alg = 'aes_128_cbc', key = PRIVATE_KEY, iv = iv, op = DECRYPT_OP)  
  buf = cipher.update(data)  
  buf = buf + cipher.final()  
  del cipher  
  return buf
data = sys.argv[1]
data = urllib.unquote(data)
data = base64.decodestring(data)
data = data.encode('hex')
print Decrypt(data)

#encrypt_data= Encrypt(data)
#encrypt_data=data.decode('hex')
#encrypt_data=base64.encodestring(encrypt_data)
#print encrypt_data