python加密解密
# -*- coding:utf8 -*-
from Crypto.Hash import MD5
from Crypto.Cipher import AES
from Crypto import Random
import socket
import uuid
import getpass
import os
#生成哈希值所用
from datetime import datetime
#获取当前时间
timeNow = datetime.now()
print timeNow
#获取当前用户名
username =getpass.getuser()
print username
#获取当前计算机名
computerName = socket.getfqdn(socket.gethostname())
print computerName
#获取MAC地址
mac=uuid.UUID(int = uuid.getnode()).hex[-12:]
print mac
#生成密钥
h = MD5.new()
h.update(str(timeNow)+username+computerName+mac)
key =h.hexdigest()
print key
#新建一个加密对象
iv = Random.new().read(AES.block_size)
cipher = AES.new(key,AES.MODE_CFB,iv)
print cipher
#测试文本
text = 'destination" : "driverOrderCommand.getSmartFindGoods'
#加密
ciphertext =cipher.encrypt(text)
print ciphertext
print len(ciphertext)
#解密
decipher = AES.new(key,AES.MODE_CFB,iv)
deciphertext = decipher.decrypt(ciphertext)
print deciphertext