最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python使用PyCrypto實現(xiàn)AES加密功能示例

 更新時間:2017年05月22日 11:54:57   作者:pythopen  
這篇文章主要介紹了Python使用PyCrypto實現(xiàn)AES加密功能,結(jié)合具體實例形式分析了PyCrypto實現(xiàn)AES加密的操作步驟與相關(guān)實現(xiàn)技巧,需要的朋友可以參考下

本文實例講述了Python使用PyCrypto實現(xiàn)AES加密功能。分享給大家供大家參考,具體如下:

#!/usr/bin/env python
from Crypto.Cipher import AES
import base64
import os
# the block size for the cipher object; must be 16, 24, or 32 for AES
BLOCK_SIZE = 32
# the character used for padding--with a block cipher such as AES, the value
# you encrypt must be a multiple of BLOCK_SIZE in length. This character is
# used to ensure that your value is always a multiple of BLOCK_SIZE
PADDING = '{'
# one-liner to sufficiently pad the text to be encrypted
pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING
# one-liners to encrypt/encode and decrypt/decode a string
# encrypt with AES, encode with base64
EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s)))
DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING)
# generate a random secret key
secret = os.urandom(BLOCK_SIZE)
# create a cipher object using the random secret
cipher = AES.new(secret)
# encode a string
encoded = EncodeAES(cipher, 'password')
print 'Encrypted string:', encoded
# decode the encoded string
decoded = DecodeAES(cipher, encoded)
print 'Decrypted string:', decoded

PS:關(guān)于加密解密感興趣的朋友還可以參考本站在線工具:

文字在線加密解密工具(包含AES、DES、RC4等):
http://tools.jb51.net/password/txt_encode

MD5在線加密工具:
http://tools.jb51.net/password/CreateMD5Password

在線散列/哈希算法加密工具:
http://tools.jb51.net/password/hash_encrypt

在線MD5/hash/SHA-1/SHA-2/SHA-256/SHA-512/SHA-3/RIPEMD-160加密工具:
http://tools.jb51.net/password/hash_md5_sha

在線sha1/sha224/sha256/sha384/sha512加密工具:
http://tools.jb51.net/password/sha_encode

更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python編碼操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python Socket編程技巧總結(jié)》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進(jìn)階經(jīng)典教程》及《Python文件與目錄操作技巧匯總

希望本文所述對大家Python程序設(shè)計有所幫助。

相關(guān)文章

最新評論

巢湖市| 阳城县| 闽侯县| 辽宁省| 滨海县| 巩义市| 利津县| 信丰县| 长乐市| 台中市| 绥棱县| 翼城县| 长白| 普定县| 墨脱县| 永新县| 图们市| 游戏| 玉门市| 鹿泉市| 长寿区| 汉沽区| 白玉县| 双辽市| 尉氏县| 霍邱县| 永平县| 高安市| 冷水江市| 锦州市| 望城县| 赫章县| 大港区| 临汾市| 揭西县| 定日县| 疏附县| 休宁县| 吉首市| 涪陵区| 宁陕县|