Chinaunix首页 | 论坛 | 博客
  • 博客访问: 344397
  • 博文数量: 306
  • 博客积分: 3975
  • 博客等级: 中校
  • 技术积分: 3265
  • 用 户 组: 普通用户
  • 注册时间: 2007-11-27 13:14
文章分类

全部博文(306)

文章存档

2017年(1)

2016年(3)

2015年(11)

2014年(15)

2013年(178)

2012年(41)

2011年(38)

2010年(9)

2009年(9)

2008年(1)

分类: LINUX

2014-10-23 13:50:57

#!/bin/env python
#-*- coding:utf8 -*-

from Crypto.Cipher import AES
import base64


def aes_encode(text):
    BS = AES.block_size
    pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS)
    unpad = lambda s : s[0:-ord(s[-1])]
    key = 'gua*nyuhuaxia*gkaifasunweis*heng'
    iv = 'sun1we9is8he1ngw'
    mode = AES.MODE_CBC

    cipher = AES.new(key, mode, iv)
    encrypted = base64.encodestring(cipher.encrypt(pad(text)))
    return encrypted


def aes_decode(text):
    BS = AES.block_size
    pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS)
    unpad = lambda s : s[0:-ord(s[-1])]
    key = 'gua*nyuhuaxia*gkaifasunweis*heng'
    iv = 'sun1we9is8he1ngw'
    mode = AES.MODE_CBC

    str = base64.decodestring(text)
    cipher = AES.new(key, mode, iv)
    plain = unpad(cipher.decrypt(str))
    return plain

if __name__ == '__main__':
    text = '6NFcmF8EX2s/REoGe+1tAg=='
    print aes_decode(text)
阅读(1248) | 评论(0) | 转发(0) |
0

上一篇:UDP 流量攻击

下一篇:KVM虚拟机应用扩容

给主人留下些什么吧!~~